diff options
Diffstat (limited to 'tests/float/tfloat4.nim')
-rw-r--r-- | tests/float/tfloat4.nim | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/tests/float/tfloat4.nim b/tests/float/tfloat4.nim index 68df56be8..2bb61eb58 100644 --- a/tests/float/tfloat4.nim +++ b/tests/float/tfloat4.nim @@ -1,15 +1,14 @@ discard """ - file: "tfloat4.nim" output: "passed all tests." - exitcode: 0 """ -import math, strutils + +import strutils proc c_sprintf(buf, fmt: cstring) {.importc:"sprintf", header: "<stdio.h>", varargs.} proc floatToStr(f: float64): string = var buffer: array[128, char] - c_sprintf(addr buffer, "%.16e", f) + c_sprintf(cast[cstring](addr buffer), "%.16e", f) result = "" for ch in buffer: if ch == '\0': @@ -55,4 +54,16 @@ doAssert 9999999999999999.0 == "9999999999999999.0".parseFloat doAssert 0.999999999999999 == ".999999999999999".parseFloat doAssert 0.9999999999999999 == ".9999999999999999".parseFloat +# bug #18400 +var s = [-13.888888'f32] +doAssert $s[0] == "-13.888888" +var x = 1.23456789012345'f32 +doAssert $x == "1.2345679" + +# bug #21847 +doAssert parseFloat"0e+42" == 0.0 +doAssert parseFloat"0e+42949672969" == 0.0 +doAssert parseFloat"0e+42949672970" == 0.0 +doAssert parseFloat"0e+42949623223346323563272970" == 0.0 + echo("passed all tests.") |