@@ -12,6 +12,17 @@ import strconv
12
12
// str return a `f64` as `string` in suitable notation.
13
13
[inline ]
14
14
pub fn (x f64) str () string {
15
+ unsafe {
16
+ f := strconv.Float64 u{
17
+ f: x
18
+ }
19
+ if f.u == strconv.double_minus_zero {
20
+ return '-0'
21
+ }
22
+ if f.u == strconv.double_plus_zero {
23
+ return '0'
24
+ }
25
+ }
15
26
abs_x := f64_abs (x)
16
27
if abs_x > = 0.0001 && abs_x < 1.0e6 {
17
28
return strconv.f64_to_str_l (x)
@@ -20,6 +31,20 @@ pub fn (x f64) str() string {
20
31
}
21
32
}
22
33
34
+ // strg return a `f64` as `string` in "g" printf format
35
+ [inline ]
36
+ pub fn (x f64) strg () string {
37
+ if x == 0 {
38
+ return '0'
39
+ }
40
+ abs_x := f64_abs (x)
41
+ if abs_x > = 0.0001 && abs_x < 1.0e6 {
42
+ return strconv.f64_to_str_l_no_dot (x)
43
+ } else {
44
+ return strconv.ftoa_64 (x)
45
+ }
46
+ }
47
+
23
48
// str returns the value of the `float_literal` as a `string`.
24
49
[inline ]
25
50
pub fn (d float_literal) str () string {
@@ -53,6 +78,17 @@ pub fn (x f64) strlong() string {
53
78
// str returns a `f32` as `string` in suitable notation.
54
79
[inline ]
55
80
pub fn (x f32) str () string {
81
+ unsafe {
82
+ f := strconv.Float32 u{
83
+ f: x
84
+ }
85
+ if f.u == strconv.single_minus_zero {
86
+ return '-0'
87
+ }
88
+ if f.u == strconv.single_plus_zero {
89
+ return '0'
90
+ }
91
+ }
56
92
abs_x := f32_abs (x)
57
93
if abs_x > = 0.0001 && abs_x < 1.0e6 {
58
94
return strconv.f32_to_str_l (x)
@@ -61,6 +97,20 @@ pub fn (x f32) str() string {
61
97
}
62
98
}
63
99
100
+ // strg return a `f32` as `string` in "g" printf format
101
+ [inline ]
102
+ pub fn (x f32) strg () string {
103
+ if x == 0 {
104
+ return '0'
105
+ }
106
+ abs_x := f32_abs (x)
107
+ if abs_x > = 0.0001 && abs_x < 1.0e6 {
108
+ return strconv.f32_to_str_l_no_dot (x)
109
+ } else {
110
+ return strconv.ftoa_32 (x)
111
+ }
112
+ }
113
+
64
114
// strsci returns the `f32` as a `string` in scientific notation with `digit_num` deciamals displayed, max 8 digits.
65
115
// Example: assert f32(1.234).strsci(3) == '1.234e+00'
66
116
[inline ]
0 commit comments