1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

atof: lots of fixes

* removed sprintf for f64 and f32 use

* removed all pointers from the code, used unions instead

* solved module name problem

* fixed tests on vlib/math

* fix for alpine-linux math test

* small fix on byte allocation for ftoa
This commit is contained in:
penguindark
2020-02-26 12:14:06 +01:00
committed by GitHub
parent c4e83faa57
commit 39429f7ac9
9 changed files with 180 additions and 137 deletions

View File

@ -59,8 +59,8 @@ test_cases_f32 = [
exp_result_f32 = [
"0e+00",
"-0e+00",
"NaN",
"NaN",
"nan",
"nan",
"+inf",
"-inf",
"1.e+00",
@ -111,8 +111,8 @@ test_cases_f64 = [
exp_result_f64 = [
"0e+00",
"-0e+00",
"NaN",
"NaN",
"nan",
"nan",
"+inf",
"-inf",
"1.e+00",
@ -141,7 +141,7 @@ exp_result_f64 = [
fn test_float_to_str(){
// test f32
for c,x in test_cases_f32 {
s := ftoa.f32_to_str(x,8)
s := f32_to_str(x,8)
s1 := exp_result_f32[c]
//println("$s1 $s")
assert s == s1
@ -149,7 +149,7 @@ fn test_float_to_str(){
// test f64
for c,x in test_cases_f64 {
s := ftoa.f64_to_str(x,17)
s := f64_to_str(x,17)
s1 := exp_result_f64[c]
//println("$s1 $s")
assert s == s1
@ -157,11 +157,11 @@ fn test_float_to_str(){
// test long format
for exp := 1 ; exp < 120 ; exp++ {
a :=ftoa.f64_to_str_l(("1e"+exp.str()).f64())
a := f64_to_str_l(("1e"+exp.str()).f64())
//println(a)
assert a.len == exp + 1
b :=ftoa.f64_to_str_l(("1e-"+exp.str()).f64())
b := f64_to_str_l(("1e-"+exp.str()).f64())
//println(b)
assert b.len == exp + 2
}