Thank you for your interest in contributing to the float8 library! This document provides guidelines and information for contributors.
- Code of Conduct
- Getting Started
- Development Setup
- Contributing Guidelines
- Testing
- Code Style
- Submitting Changes
- Issue Reporting
- Performance Considerations
This project adheres to a code of conduct that promotes a welcoming and inclusive environment. Please be respectful and professional in all interactions.
- Fork the repository on GitHub
- Clone your fork locally:
git clone https://github.com/yourusername/float8.git cd float8 - Add the upstream remote:
git remote add upstream https://github.com/zerfoo/float8.git
- Go 1.21 or later
- Git
-
Install dependencies (if any):
go mod download
-
Run tests to ensure everything works:
go test ./... -
Run benchmarks:
go test -bench=. -benchmem ./...
We welcome several types of contributions:
- Bug fixes: Fix issues in existing functionality
- Performance improvements: Optimize existing algorithms
- New features: Add new mathematical functions or operations
- Documentation: Improve README, comments, or examples
- Tests: Add test cases for better coverage
- Benchmarks: Add performance benchmarks
- Check existing issues to see if your contribution is already being worked on
- Open an issue to discuss major changes before implementing them
- Keep changes focused - one feature or fix per pull request
- Correctness: All operations must be mathematically correct according to IEEE 754 FP8 E4M3FN specification
- Performance: Consider both speed and memory usage
- Compatibility: Maintain backward compatibility unless absolutely necessary
- Simplicity: Prefer clear, readable code over clever optimizations
When adding new mathematical functions:
- Follow the pattern established by existing functions
- Handle edge cases (NaN, zero, overflow/underflow)
- Add comprehensive tests including edge cases
- Include benchmarks for performance-critical functions
- Document the function with clear comments
Example function structure:
// NewFunction performs a specific mathematical operation on Float8 values.
// It handles special cases like NaN and zero appropriately.
func (f Float8) NewFunction() Float8 {
// Handle special cases first
if f.IsNaN() {
return NaN()
}
// Main implementation
// ...
return result
}- All new code must have tests
- Aim for high test coverage (>90%)
- Include edge cases and boundary conditions
- Test both normal and error paths
# Run all tests
go test ./...
# Run tests with coverage
go test -cover ./...
# Run specific test files
go test -v ./arithmetic_test.go
# Generate coverage report
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out- Unit tests: Test individual functions
- Property tests: Test mathematical properties (commutativity, associativity, etc.)
- Edge case tests: Test boundary conditions and special values
- Performance tests: Benchmark critical operations
Follow this pattern for test functions:
func TestNewFunction(t *testing.T) {
tests := []struct {
name string
input Float8
expected Float8
}{
{"normal case", FromFloat32(2.0), FromFloat32(4.0)},
{"zero", Zero(), Zero()},
{"NaN", NaN(), NaN()},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.input.NewFunction()
if !result.Equal(tt.expected) {
t.Errorf("got %v, want %v", result, tt.expected)
}
})
}
}- Follow standard Go formatting (
go fmt) - Use
go vetto check for common issues - Follow Go naming conventions
- Write clear, descriptive variable names
- Public functions must have godoc comments
- Complex algorithms should have implementation comments
- Edge cases should be documented
- Performance characteristics should be noted where relevant
// Add performs floating-point addition of two Float8 values.
// It handles special cases including NaN propagation and zero addition.
// The result follows IEEE 754 rounding rules for the E4M3FN format.
//
// Special cases:
// - Add(NaN, x) = NaN for any x
// - Add(x, NaN) = NaN for any x
// - Add(+0, -0) = +0
//
// Performance: O(1) with fast arithmetic enabled, otherwise involves
// conversion to float32 and back.
func (f Float8) Add(other Float8) Float8 {
// Implementation...
}-
Create a feature branch:
git checkout -b feature/your-feature-name
-
Make your changes following the guidelines above
-
Test thoroughly:
go test ./... go test -race ./...
-
Update documentation if needed
-
Commit with clear messages:
git commit -m "Add NewFunction for mathematical operation X - Implements IEEE 754 compliant operation - Handles NaN and zero edge cases - Includes comprehensive tests and benchmarks"
-
Push to your fork:
git push origin feature/your-feature-name
-
Open a pull request with:
- Clear description of changes
- Reference to related issues
- Test results and benchmark comparisons
- One feature per PR - keep changes focused
- Include tests for all new functionality
- Update documentation as needed
- Maintain backward compatibility unless discussed
- Follow the existing code style
When reporting bugs, please include:
- Go version and operating system
- Minimal reproduction case
- Expected vs actual behavior
- Stack trace if applicable
For new features, please provide:
- Use case description
- Proposed API design
- Performance considerations
- Compatibility impact
- Measure first - use benchmarks to identify bottlenecks
- Consider memory usage - Float8 is designed for efficiency
- Lookup tables - balance speed vs memory for critical paths
- Avoid allocations in hot paths
- Profile regularly - use
go tool pproffor analysis
Always include benchmarks for performance-critical changes:
func BenchmarkNewFunction(b *testing.B) {
f := FromFloat32(3.14)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = f.NewFunction()
}
}If you have questions about contributing, please:
- Check existing issues and documentation
- Open a new issue for discussion
- Reach out to maintainers
Thank you for contributing to float8!