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,6 +1,13 @@
import math
import math.complex as cmplx
fn tst_res(str1 string, str2 string) bool {
if (math.abs(str1.f64() - str2.f64())) < 1e-5 {
return true
}
return false
}
fn test_complex_addition() {
// Test is based on and verified from practice examples of Khan Academy
// https://www.khanacademy.org/math/precalculus/imaginary-and-complex-numbers
@ -177,14 +184,14 @@ fn test_complex_mod() {
mut c1 := cmplx.complex(5,7)
mut result := c1.mod()
// Some issue with precision comparison in f64 using == operator hence serializing to string
assert result.str().eq('8.602325')
assert tst_res(result.str(), '8.602325')
c1 = cmplx.complex(-3,4)
result = c1.mod()
assert result == 5
c1 = cmplx.complex(-1,-2)
result = c1.mod()
// Some issue with precision comparison in f64 using == operator hence serializing to string
assert result.str().eq('2.236068')
assert tst_res(result.str(), '2.236068')
}
fn test_complex_pow() {
@ -269,17 +276,17 @@ fn test_complex_arg() {
mut c2 := cmplx.complex(2.152033,0.950547)
mut result := c1.arg()
// Some issue with precision comparison in f64 using == operator hence serializing to string
assert result.str().eq('0.950547')
assert tst_res(result.str(), '0.950547')
c1 = cmplx.complex(-3,4)
c2 = cmplx.complex(1.609438,2.214297)
result = c1.arg()
// Some issue with precision comparison in f64 using == operator hence serializing to string
assert result.str().eq('2.214297')
assert tst_res(result.str(), '2.214297')
c1 = cmplx.complex(-1,-2)
c2 = cmplx.complex(0.804719,-2.034444)
result = c1.arg()
// Some issue with precision comparison in f64 using == operator hence serializing to string
assert result.str().eq('-2.034444')
assert tst_res(result.str(), '-2.034444')
}
fn test_complex_log() {