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

cgen: use standard checks for float comparisons

This commit is contained in:
Uwe Krüger
2020-06-04 19:47:41 +02:00
committed by GitHub
parent 42e314d281
commit cf9498ef6b
7 changed files with 164 additions and 203 deletions

View File

@ -122,8 +122,8 @@ fn test_complex_abs() {
mut c1 := cmplx.complex(3,4)
assert c1.abs() == 5
c1 = cmplx.complex(1,2)
assert c1.abs().eq(math.sqrt(5))
assert c1.abs().eq(c1.conjugate().abs())
assert c1.abs() == math.sqrt(5)
assert c1.abs() == c1.conjugate().abs()
c1 = cmplx.complex(7,0)
assert c1.abs() == 7
}
@ -132,17 +132,17 @@ fn test_complex_angle(){
// Test is based on and verified from practice examples of Khan Academy
// https://www.khanacademy.org/math/precalculus/imaginary-and-complex-numbers
mut c := cmplx.complex(1, 0)
assert (c.angle() * 180 / math.pi).eq(0)
assert c.angle() * 180 / math.pi == 0
c = cmplx.complex(1, 1)
assert (c.angle() * 180 / math.pi).eq(45)
assert c.angle() * 180 / math.pi == 45
c = cmplx.complex(0, 1)
assert (c.angle() * 180 / math.pi).eq(90)
assert c.angle() * 180 / math.pi == 90
c = cmplx.complex(-1, 1)
assert (c.angle() * 180 / math.pi).eq(135)
assert c.angle() * 180 / math.pi == 135
c = cmplx.complex(-1, -1)
assert (c.angle() * 180 / math.pi).eq(-135)
assert c.angle() * 180 / math.pi == -135
cc := c.conjugate()
assert (cc.angle() + c.angle()).eq(0)
assert cc.angle() + c.angle() == 0
}