Skip to content

Commit

Permalink
Document floating-point generators
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingmutant committed Aug 29, 2022
1 parent 72f36fa commit a2197e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
- explicit examples support (based on `refDraws` shrink test machinery)
- explicit settings support (to not depend on global environment)
- [go-fuzz](https://github.com/golang/proposal/blob/master/design/draft-fuzzing.md) integration
- decide what to do with FP NaNs etc.
- document every exported symbol?

## Generators

Expand Down
10 changes: 10 additions & 0 deletions floats.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,23 @@ const (
floatSignifLabel = "floatsignif"
)

// Float32 is a shorthand for Float32Range(-[math.MaxFloat32], [math.MaxFloat32]).
func Float32() *Generator[float32] {
return Float32Range(-math.MaxFloat32, math.MaxFloat32)
}

// Float32Min is a shorthand for Float32Range(min, [math.MaxFloat32]).
func Float32Min(min float32) *Generator[float32] {
return Float32Range(min, math.MaxFloat32)
}

// Float32Max is a shorthand for Float32Range(-[math.MaxFloat32], max).
func Float32Max(max float32) *Generator[float32] {
return Float32Range(-math.MaxFloat32, max)
}

// Float32Range returns a generator of 32-bit floating-point numbers in range [min, max].
// Both min and max can be infinite.
func Float32Range(min float32, max float32) *Generator[float32] {
assertf(min == min, "min should not be a NaN")
assertf(max == max, "max should not be a NaN")
Expand All @@ -50,18 +55,23 @@ func Float32Range(min float32, max float32) *Generator[float32] {
})
}

// Float64 is a shorthand for Float64Range(-[math.MaxFloat64], [math.MaxFloat64]).
func Float64() *Generator[float64] {
return Float64Range(-math.MaxFloat64, math.MaxFloat64)
}

// Float64Min is a shorthand for Float64Range(min, [math.MaxFloat64]).
func Float64Min(min float64) *Generator[float64] {
return Float64Range(min, math.MaxFloat64)
}

// Float64Max is a shorthand for Float64Range(-[math.MaxFloat64], max).
func Float64Max(max float64) *Generator[float64] {
return Float64Range(-math.MaxFloat64, max)
}

// Float64Range returns a generator of 64-bit floating-point numbers in range [min, max].
// Both min and max can be infinite.
func Float64Range(min float64, max float64) *Generator[float64] {
assertf(min == min, "min should not be a NaN")
assertf(max == max, "max should not be a NaN")
Expand Down

0 comments on commit a2197e6

Please sign in to comment.