• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

enetx / g / 16991077829

15 Aug 2025 01:32PM UTC coverage: 88.742% (-0.2%) from 88.915%
16991077829

push

github

enetx
ref opt

283 of 305 new or added lines in 16 files covered. (92.79%)

4 existing lines in 4 files now uncovered.

4296 of 4841 relevant lines covered (88.74%)

866.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.97
/float.go
1
package g
2

3
import (
4
        "fmt"
5
        "math"
6
        "math/big"
7
        "strconv"
8

9
        "github.com/enetx/g/cmp"
10
        "github.com/enetx/g/constraints"
11
)
12

13
// NewFloat creates a new Float with the provided value.
14
func NewFloat[T constraints.Float | constraints.Integer](float T) Float { return Float(float) }
1✔
15

16
// Transform applies a transformation function to the Float and returns the result.
17
func (f Float) Transform(fn func(Float) Float) Float { return fn(f) }
2✔
18

19
// Min returns the minimum of two Floats.
20
func (f Float) Min(b ...Float) Float { return cmp.Min(append(b, f)...) }
1✔
21

22
// Max returns the maximum of two Floats.
23
func (f Float) Max(b ...Float) Float { return cmp.Max(append(b, f)...) }
1✔
24

25
// Abs returns the absolute value of the Float.
26
func (f Float) Abs() Float { return Float(math.Abs(f.Std())) }
3✔
27

28
// Add adds two Floats and returns the result.
29
func (f Float) Add(b Float) Float { return f + b }
2✔
30

31
// BigFloat returns the Float as a *big.Float.
32
func (f Float) BigFloat() *big.Float { return big.NewFloat(f.Std()) }
3✔
33

34
// Cmp compares two Floats and returns an cmp.Ordering.
35
func (f Float) Cmp(b Float) cmp.Ordering { return cmp.Cmp(f, b) }
51✔
36

37
// Div divides two Floats and returns the result.
38
func (f Float) Div(b Float) Float { return f / b }
1✔
39

40
// IsZero checks if the Float is 0.
41
func (f Float) IsZero() bool { return f.Eq(0) }
3✔
42

43
// Eq checks if two Floats are equal.
44
func (f Float) Eq(b Float) bool { return f.Cmp(b).IsEq() }
39✔
45

46
// Std returns the Float as a float64.
47
func (f Float) Std() float64 { return float64(f) }
47✔
48

49
// Gt checks if the Float is greater than the specified Float.
50
func (f Float) Gt(b Float) bool { return f.Cmp(b).IsGt() }
4✔
51

52
// Int returns the Float as an Int.
53
func (f Float) Int() Int { return Int(f) }
3✔
54

55
// String returns the Float as an String.
56
func (f Float) String() String { return String(strconv.FormatFloat(f.Std(), 'g', -1, 64)) }
3✔
57

58
// Lt checks if the Float is less than the specified Float.
59
func (f Float) Lt(b Float) bool { return f.Cmp(b).IsLt() }
4✔
60

61
// Mul multiplies two Floats and returns the result.
62
func (f Float) Mul(b Float) Float { return f * b }
22✔
63

64
// Ne checks if two Floats are not equal.
65
func (f Float) Ne(b Float) bool { return !f.Eq(b) }
32✔
66

67
// Round rounds the Float to the nearest integer and returns the result as an Int.
68
func (f Float) Round() Int {
7✔
69
        return Int(math.Round(f.Std()))
7✔
70
}
7✔
71

72
// RoundDecimal rounds the Float value to the specified number of decimal places.
73
//
74
// The function takes the number of decimal places (precision) as an argument and returns a new
75
// Float value rounded to that number of decimals. This is achieved by multiplying the Float
76
// value by a power of 10 equal to the desired precision, rounding the result, and then dividing
77
// the rounded result by the same power of 10.
78
//
79
// Parameters:
80
//
81
// - precision (Int): The number of decimal places to round the Float value to.
82
//
83
// Returns:
84
//
85
// - Float: A new Float value rounded to the specified number of decimal places.
86
//
87
// Example usage:
88
//
89
//        f := g.Float(3.14159)
90
//        rounded := f.RoundDecimal(2) // rounded will be 3.14
91
func (f Float) RoundDecimal(precision Int) Float {
31✔
92
        if precision < 0 {
32✔
93
                return f
1✔
94
        }
1✔
95

96
        pow := math.Pow10(precision.Std())
30✔
97

30✔
98
        return Float(math.Round(f.Std()*pow) / pow)
30✔
99
}
100

101
// Sub subtracts two Floats and returns the result.
102
func (f Float) Sub(b Float) Float { return f - b }
22✔
103

104
// Bits returns IEEE-754 representation of f.
NEW
105
func (f Float) Bits() uint64 { return math.Float64bits(f.Std()) }
×
106

107
// Float32 returns the Float as a float32.
108
func (f Float) Float32() float32 { return float32(f) }
3✔
109

110
// Print writes the value of the Float to the standard output (console)
111
// and returns the Float unchanged.
112
func (f Float) Print() Float { fmt.Print(f); return f }
1✔
113

114
// Println writes the value of the Float to the standard output (console) with a newline
115
// and returns the Float unchanged.
116
func (f Float) Println() Float { fmt.Println(f); return f }
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc