We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 962ab4a commit 5b585dcCopy full SHA for 5b585dc
4 files changed
lib/builtin/number.c.bt
@@ -54,15 +54,15 @@ pub fun (n u64) str() string {
54
}
55
56
pub fun (n f32) str() string {
57
- length := #C.snprintf(#C.'NULL' as &u8, 0, "%g".str, n as f64)
+ length := #C.snprintf(#C.'NULL' as &u8, 0, "%.9g".str, n as f64)
58
buf := #C.malloc(length + 1)
59
- _ = #C.snprintf(buf, length + 1, "%g".str, n as f64)
+ _ = #C.snprintf(buf, length + 1, "%.9g".str, n as f64)
60
return from_c_string(buf)
61
62
63
pub fun (n f64) str() string {
64
- length := #C.snprintf(#C.'NULL' as &u8, 0, "%g".str, n)
+ length := #C.snprintf(#C.'NULL' as &u8, 0, "%.17g".str, n)
65
66
- _ = #C.snprintf(buf, length + 1, "%g".str, n)
+ _ = #C.snprintf(buf, length + 1, "%.17g".str, n)
67
68
tests/auto_str/auto_str_test.bt
@@ -5,3 +5,16 @@ fun test_array() {
5
a := [true, false, true]
6
assert a.str() == "[true, false, true]"
7
8
+
9
+struct Bar {
10
+ f f64
11
+}
12
13
+fun test_struct() {
14
+ b := Bar {
15
+ f = 3.14
16
+ }
17
+ assert b.str() == 'Bar{
18
19
+}'
20
tests/auto_str/auto_str_test.js.bt
@@ -10,7 +10,6 @@ fun test_map() {
assert m.str() == "{'foo': 62, 'bar': 31}"
-// TODO C floats
struct Bar {
f f64
@@ -19,15 +18,7 @@ struct Foo {
b Bar
21
22
-fun test_struct() {
23
- b := Bar {
24
- f = 3.14
25
- }
26
- assert b.str() == 'Bar{
27
28
-}'
29
-}
30
-
+// TODO C fix nested structs
31
fun test_nested_struct() {
32
f := Foo {}
33
assert f.str() == 'Foo{
tests/auto_str/float_precision_test.bt
@@ -0,0 +1,7 @@
1
+// SPDX-FileCopyrightText: Lukas Neubert
2
+// SPDX-License-Identifier: MIT
3
4
+fun test_float_str_precision() {
+ f := 123.45678901234567890
+ assert f.str() == '123.45678901234568'
0 commit comments