-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdecimal64_debug.go
54 lines (43 loc) · 1.1 KB
/
decimal64_debug.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//go:build decimal_debug
// +build decimal_debug
package decimal
import "fmt"
// Decimal64 represents an IEEE 754 64-bit floating point decimal number.
// It uses the binary representation method.
// Decimal64 is intentionally a struct to ensure users don't accidentally cast it to uint64.
type Decimal64 struct {
s string
fl flavor
sign int8
exp int16
significand uint64
bits uint64
}
func new64(bits uint64) Decimal64 {
d := new64nostr(bits)
d.s = d.String()
return d
}
func new64str(bits uint64, s string) Decimal64 {
d := new64nostr(bits)
d.s = s
return d
}
func new64nostr(bits uint64) Decimal64 {
d := Decimal64{bits: bits}
fl, sign, exp, significand := d.parts()
d.fl = fl
d.sign = sign
d.exp = exp
d.significand = significand
d.bits = d.bits
return d
}
func checkSignificandIsNormal(significand uint64) {
if decimal64Base > significand {
panic(fmt.Errorf("Failed logic check: %d <= %d", decimal64Base, significand))
}
if significand >= 10*decimal64Base {
panic(fmt.Errorf("Failed logic check: %d < %d", significand, 10*decimal64Base))
}
}