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

@ -1,5 +1,12 @@
module math
fn tst_res(str1 string, str2 string) bool {
if (math.abs(str1.f64() - str2.f64())) < 1e-5 {
return true
}
return false
}
fn test_gcd() {
assert gcd(6, 9) == 3
assert gcd(6, -9) == 3
@ -39,8 +46,10 @@ fn test_gamma() {
assert gamma(1) == 1
assert gamma(5) == 24
sval := '2.453737'
assert log_gamma(4.5).str() == sval
assert log(gamma(4.5)).str() == sval
assert tst_res(log_gamma(4.5).str(), sval)
assert tst_res(log(gamma(4.5)).str(), sval)
//assert log_gamma(4.5).str() == sval
//assert log(gamma(4.5)).str() == sval
assert abs( log_gamma(4.5) - log(gamma(4.5)) ) < 0.000001
// assert log_gamma(4.5) == log(gamma(4.5)) /* <-- fails on alpine/musl
}