mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
move Complex logic to cmath
It was causing problems with cross compiling for Linux, and it should be a separate module anyway, just like in Go and Python.
This commit is contained in:
parent
3d4cd0bbc0
commit
e1a6453302
@ -2,7 +2,9 @@
|
|||||||
// Use of this source code is governed by an MIT license
|
// Use of this source code is governed by an MIT license
|
||||||
// that can be found in the LICENSE file.
|
// that can be found in the LICENSE file.
|
||||||
|
|
||||||
module math
|
module cmath
|
||||||
|
|
||||||
|
import math
|
||||||
|
|
||||||
struct Complex {
|
struct Complex {
|
||||||
re f64
|
re f64
|
||||||
@ -38,7 +40,7 @@ pub fn (c Complex) mod() f64 {
|
|||||||
|
|
||||||
// Complex Angle
|
// Complex Angle
|
||||||
pub fn (c Complex) angle() f64 {
|
pub fn (c Complex) angle() f64 {
|
||||||
return atan2(c.im, c.re)
|
return math.atan2(c.im, c.re)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Complex Addition c1 + c2
|
// Complex Addition c1 + c2
|
||||||
@ -123,11 +125,11 @@ pub fn (c Complex) mulinv() Complex {
|
|||||||
// Based on
|
// Based on
|
||||||
// https://www.khanacademy.org/math/precalculus/imaginary-and-complex-numbers/multiplying-and-dividing-complex-numbers-in-polar-form/a/complex-number-polar-form-review
|
// https://www.khanacademy.org/math/precalculus/imaginary-and-complex-numbers/multiplying-and-dividing-complex-numbers-in-polar-form/a/complex-number-polar-form-review
|
||||||
pub fn (c Complex) pow(n f64) Complex {
|
pub fn (c Complex) pow(n f64) Complex {
|
||||||
r := pow(c.abs(), n)
|
r := math.pow(c.abs(), n)
|
||||||
angle := c.angle()
|
angle := c.angle()
|
||||||
return Complex {
|
return Complex {
|
||||||
r * cos(n * angle),
|
r * math.cos(n * angle),
|
||||||
r * sin(n * angle)
|
r * math.sin(n * angle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,10 +143,10 @@ pub fn (c Complex) root(n f64) Complex {
|
|||||||
// Based on
|
// Based on
|
||||||
// https://www.math.wisc.edu/~angenent/Free-Lecture-Notes/freecomplexnumbers.pdf
|
// https://www.math.wisc.edu/~angenent/Free-Lecture-Notes/freecomplexnumbers.pdf
|
||||||
pub fn (c Complex) exp() Complex {
|
pub fn (c Complex) exp() Complex {
|
||||||
a := exp(c.re)
|
a := math.exp(c.re)
|
||||||
return Complex {
|
return Complex {
|
||||||
a * cos(c.im),
|
a * math.cos(c.im),
|
||||||
a * sin(c.im)
|
a * math.sin(c.im)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +155,7 @@ pub fn (c Complex) exp() Complex {
|
|||||||
// http://www.chemistrylearning.com/logarithm-of-complex-number/
|
// http://www.chemistrylearning.com/logarithm-of-complex-number/
|
||||||
pub fn (c Complex) ln() Complex {
|
pub fn (c Complex) ln() Complex {
|
||||||
return Complex {
|
return Complex {
|
||||||
log(c.abs()),
|
math.log(c.abs()),
|
||||||
c.angle()
|
c.angle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,8 +165,8 @@ pub fn (c Complex) ln() Complex {
|
|||||||
// http://www.milefoot.com/math/complex/functionsofi.htm
|
// http://www.milefoot.com/math/complex/functionsofi.htm
|
||||||
pub fn (c Complex) sin() Complex {
|
pub fn (c Complex) sin() Complex {
|
||||||
return Complex{
|
return Complex{
|
||||||
sin(c.re) * cosh(c.im),
|
math.sin(c.re) * math.cosh(c.im),
|
||||||
cos(c.re) * sinh(c.im)
|
math.cos(c.re) * math.sinh(c.im)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,8 +175,8 @@ pub fn (c Complex) sin() Complex {
|
|||||||
// http://www.milefoot.com/math/complex/functionsofi.htm
|
// http://www.milefoot.com/math/complex/functionsofi.htm
|
||||||
pub fn (c Complex) cos() Complex {
|
pub fn (c Complex) cos() Complex {
|
||||||
return Complex{
|
return Complex{
|
||||||
cos(c.re) * cosh(c.im),
|
math.cos(c.re) * math.cosh(c.im),
|
||||||
-(sin(c.re) * sinh(c.im))
|
-(math.sin(c.re) * math.sinh(c.im))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,8 +192,8 @@ pub fn (c Complex) tan() Complex {
|
|||||||
// http://www.milefoot.com/math/complex/functionsofi.htm
|
// http://www.milefoot.com/math/complex/functionsofi.htm
|
||||||
pub fn (c Complex) sinh() Complex {
|
pub fn (c Complex) sinh() Complex {
|
||||||
return Complex{
|
return Complex{
|
||||||
cos(c.im) * sinh(c.re),
|
math.cos(c.im) * math.sinh(c.re),
|
||||||
sin(c.im) * cosh(c.re)
|
math.sin(c.im) * math.cosh(c.re)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,8 +202,8 @@ pub fn (c Complex) sinh() Complex {
|
|||||||
// http://www.milefoot.com/math/complex/functionsofi.htm
|
// http://www.milefoot.com/math/complex/functionsofi.htm
|
||||||
pub fn (c Complex) cosh() Complex {
|
pub fn (c Complex) cosh() Complex {
|
||||||
return Complex{
|
return Complex{
|
||||||
cos(c.im) * cosh(c.re),
|
math.cos(c.im) * math.cosh(c.re),
|
||||||
sin(c.im) * sinh(c.re)
|
math.sin(c.im) * math.sinh(c.re)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,128 +1,129 @@
|
|||||||
import math
|
import math
|
||||||
|
import cmath
|
||||||
|
|
||||||
// Tests are based on and verified from practice examples of Khan Academy
|
// Tests are based on and verified from practice examples of Khan Academy
|
||||||
// https://www.khanacademy.org/math/precalculus/imaginary-and-complex-numbers
|
// https://www.khanacademy.org/math/precalculus/imaginary-and-complex-numbers
|
||||||
|
|
||||||
fn test_complex_addition() {
|
fn test_complex_addition() {
|
||||||
mut c1 := math.complex(0,-10)
|
mut c1 := cmath.complex(0,-10)
|
||||||
mut c2 := math.complex(-40,8)
|
mut c2 := cmath.complex(-40,8)
|
||||||
mut result := c1 + c2
|
mut result := c1 + c2
|
||||||
assert result.equals(math.complex(-40,-2))
|
assert result.equals(cmath.complex(-40,-2))
|
||||||
c1 = math.complex(-71,2)
|
c1 = cmath.complex(-71,2)
|
||||||
c2 = math.complex(88,-12)
|
c2 = cmath.complex(88,-12)
|
||||||
result = c1 + c2
|
result = c1 + c2
|
||||||
assert result.equals(math.complex(17,-10))
|
assert result.equals(cmath.complex(17,-10))
|
||||||
c1 = math.complex(0,-30)
|
c1 = cmath.complex(0,-30)
|
||||||
c2 = math.complex(52,-30)
|
c2 = cmath.complex(52,-30)
|
||||||
result = c1 + c2
|
result = c1 + c2
|
||||||
assert result.equals(math.complex(52,-60))
|
assert result.equals(cmath.complex(52,-60))
|
||||||
c1 = math.complex(12,-9)
|
c1 = cmath.complex(12,-9)
|
||||||
c2 = math.complex(32,-6)
|
c2 = cmath.complex(32,-6)
|
||||||
result = c1 + c2
|
result = c1 + c2
|
||||||
assert result.equals(math.complex(44,-15))
|
assert result.equals(cmath.complex(44,-15))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_complex_subtraction() {
|
fn test_complex_subtraction() {
|
||||||
mut c1 := math.complex(-8,0)
|
mut c1 := cmath.complex(-8,0)
|
||||||
mut c2 := math.complex(6,30)
|
mut c2 := cmath.complex(6,30)
|
||||||
mut result := c1 - c2
|
mut result := c1 - c2
|
||||||
assert result.equals(math.complex(-14,-30))
|
assert result.equals(cmath.complex(-14,-30))
|
||||||
c1 = math.complex(-19,7)
|
c1 = cmath.complex(-19,7)
|
||||||
c2 = math.complex(29,32)
|
c2 = cmath.complex(29,32)
|
||||||
result = c1 - c2
|
result = c1 - c2
|
||||||
assert result.equals(math.complex(-48,-25))
|
assert result.equals(cmath.complex(-48,-25))
|
||||||
c1 = math.complex(12,0)
|
c1 = cmath.complex(12,0)
|
||||||
c2 = math.complex(23,13)
|
c2 = cmath.complex(23,13)
|
||||||
result = c1 - c2
|
result = c1 - c2
|
||||||
assert result.equals(math.complex(-11,-13))
|
assert result.equals(cmath.complex(-11,-13))
|
||||||
c1 = math.complex(-14,3)
|
c1 = cmath.complex(-14,3)
|
||||||
c2 = math.complex(0,14)
|
c2 = cmath.complex(0,14)
|
||||||
result = c1 - c2
|
result = c1 - c2
|
||||||
assert result.equals(math.complex(-14,-11))
|
assert result.equals(cmath.complex(-14,-11))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_complex_multiplication() {
|
fn test_complex_multiplication() {
|
||||||
mut c1 := math.complex(1,2)
|
mut c1 := cmath.complex(1,2)
|
||||||
mut c2 := math.complex(1,-4)
|
mut c2 := cmath.complex(1,-4)
|
||||||
mut result := c1.multiply(c2)
|
mut result := c1.multiply(c2)
|
||||||
assert result.equals(math.complex(9,-2))
|
assert result.equals(cmath.complex(9,-2))
|
||||||
c1 = math.complex(-4,-4)
|
c1 = cmath.complex(-4,-4)
|
||||||
c2 = math.complex(-5,-3)
|
c2 = cmath.complex(-5,-3)
|
||||||
result = c1.multiply(c2)
|
result = c1.multiply(c2)
|
||||||
assert result.equals(math.complex(8,32))
|
assert result.equals(cmath.complex(8,32))
|
||||||
c1 = math.complex(4,4)
|
c1 = cmath.complex(4,4)
|
||||||
c2 = math.complex(-2,-5)
|
c2 = cmath.complex(-2,-5)
|
||||||
result = c1.multiply(c2)
|
result = c1.multiply(c2)
|
||||||
assert result.equals(math.complex(12,-28))
|
assert result.equals(cmath.complex(12,-28))
|
||||||
c1 = math.complex(2,-2)
|
c1 = cmath.complex(2,-2)
|
||||||
c2 = math.complex(4,-4)
|
c2 = cmath.complex(4,-4)
|
||||||
result = c1.multiply(c2)
|
result = c1.multiply(c2)
|
||||||
assert result.equals(math.complex(0,-16))
|
assert result.equals(cmath.complex(0,-16))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_complex_division() {
|
fn test_complex_division() {
|
||||||
mut c1 := math.complex(-9,-6)
|
mut c1 := cmath.complex(-9,-6)
|
||||||
mut c2 := math.complex(-3,-2)
|
mut c2 := cmath.complex(-3,-2)
|
||||||
mut result := c1.divide(c2)
|
mut result := c1.divide(c2)
|
||||||
assert result.equals(math.complex(3,0))
|
assert result.equals(cmath.complex(3,0))
|
||||||
c1 = math.complex(-23,11)
|
c1 = cmath.complex(-23,11)
|
||||||
c2 = math.complex(5,1)
|
c2 = cmath.complex(5,1)
|
||||||
result = c1.divide(c2)
|
result = c1.divide(c2)
|
||||||
assert result.equals(math.complex(-4,3))
|
assert result.equals(cmath.complex(-4,3))
|
||||||
c1 = math.complex(8,-2)
|
c1 = cmath.complex(8,-2)
|
||||||
c2 = math.complex(-4,1)
|
c2 = cmath.complex(-4,1)
|
||||||
result = c1.divide(c2)
|
result = c1.divide(c2)
|
||||||
assert result.equals(math.complex(-2,0))
|
assert result.equals(cmath.complex(-2,0))
|
||||||
c1 = math.complex(11,24)
|
c1 = cmath.complex(11,24)
|
||||||
c2 = math.complex(-4,-1)
|
c2 = cmath.complex(-4,-1)
|
||||||
result = c1.divide(c2)
|
result = c1.divide(c2)
|
||||||
assert result.equals(math.complex(-4,-5))
|
assert result.equals(cmath.complex(-4,-5))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_complex_conjugate() {
|
fn test_complex_conjugate() {
|
||||||
mut c1 := math.complex(0,8)
|
mut c1 := cmath.complex(0,8)
|
||||||
mut result := c1.conjugate()
|
mut result := c1.conjugate()
|
||||||
assert result.equals(math.complex(0,-8))
|
assert result.equals(cmath.complex(0,-8))
|
||||||
c1 = math.complex(7,3)
|
c1 = cmath.complex(7,3)
|
||||||
result = c1.conjugate()
|
result = c1.conjugate()
|
||||||
assert result.equals(math.complex(7,-3))
|
assert result.equals(cmath.complex(7,-3))
|
||||||
c1 = math.complex(2,2)
|
c1 = cmath.complex(2,2)
|
||||||
result = c1.conjugate()
|
result = c1.conjugate()
|
||||||
assert result.equals(math.complex(2,-2))
|
assert result.equals(cmath.complex(2,-2))
|
||||||
c1 = math.complex(7,0)
|
c1 = cmath.complex(7,0)
|
||||||
result = c1.conjugate()
|
result = c1.conjugate()
|
||||||
assert result.equals(math.complex(7,0))
|
assert result.equals(cmath.complex(7,0))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_complex_equals() {
|
fn test_complex_equals() {
|
||||||
mut c1 := math.complex(0,8)
|
mut c1 := cmath.complex(0,8)
|
||||||
mut c2 := math.complex(0,8)
|
mut c2 := cmath.complex(0,8)
|
||||||
assert c1.equals(c2)
|
assert c1.equals(c2)
|
||||||
c1 = math.complex(-3,19)
|
c1 = cmath.complex(-3,19)
|
||||||
c2 = math.complex(-3,19)
|
c2 = cmath.complex(-3,19)
|
||||||
assert c1.equals(c2)
|
assert c1.equals(c2)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_complex_abs() {
|
fn test_complex_abs() {
|
||||||
mut c1 := math.complex(3,4)
|
mut c1 := cmath.complex(3,4)
|
||||||
assert c1.abs() == 5
|
assert c1.abs() == 5
|
||||||
c1 = math.complex(1,2)
|
c1 = cmath.complex(1,2)
|
||||||
assert c1.abs() == math.sqrt(5)
|
assert c1.abs() == math.sqrt(5)
|
||||||
assert c1.abs() == c1.conjugate().abs()
|
assert c1.abs() == c1.conjugate().abs()
|
||||||
c1 = math.complex(7,0)
|
c1 = cmath.complex(7,0)
|
||||||
assert c1.abs() == 7
|
assert c1.abs() == 7
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_complex_angle(){
|
fn test_complex_angle(){
|
||||||
mut c := math.complex(1, 0)
|
mut c := cmath.complex(1, 0)
|
||||||
assert c.angle() * 180 / math.Pi == 0
|
assert c.angle() * 180 / math.Pi == 0
|
||||||
c = math.complex(1, 1)
|
c = cmath.complex(1, 1)
|
||||||
assert c.angle() * 180 / math.Pi == 45
|
assert c.angle() * 180 / math.Pi == 45
|
||||||
c = math.complex(0, 1)
|
c = cmath.complex(0, 1)
|
||||||
assert c.angle() * 180 / math.Pi == 90
|
assert c.angle() * 180 / math.Pi == 90
|
||||||
c = math.complex(-1, 1)
|
c = cmath.complex(-1, 1)
|
||||||
assert c.angle() * 180 / math.Pi == 135
|
assert c.angle() * 180 / math.Pi == 135
|
||||||
c = math.complex(-1, -1)
|
c = cmath.complex(-1, -1)
|
||||||
assert c.angle() * 180 / math.Pi == -135
|
assert c.angle() * 180 / math.Pi == -135
|
||||||
mut cc := c.conjugate()
|
mut cc := c.conjugate()
|
||||||
assert cc.angle() + c.angle() == 0
|
assert cc.angle() + c.angle() == 0
|
||||||
@ -131,47 +132,47 @@ fn test_complex_angle(){
|
|||||||
|
|
||||||
fn test_complex_addinv() {
|
fn test_complex_addinv() {
|
||||||
// Tests were also verified on Wolfram Alpha
|
// Tests were also verified on Wolfram Alpha
|
||||||
mut c1 := math.complex(5,7)
|
mut c1 := cmath.complex(5,7)
|
||||||
mut c2 := math.complex(-5,-7)
|
mut c2 := cmath.complex(-5,-7)
|
||||||
mut result := c1.addinv()
|
mut result := c1.addinv()
|
||||||
assert result.equals(c2)
|
assert result.equals(c2)
|
||||||
c1 = math.complex(-3,4)
|
c1 = cmath.complex(-3,4)
|
||||||
c2 = math.complex(3,-4)
|
c2 = cmath.complex(3,-4)
|
||||||
result = c1.addinv()
|
result = c1.addinv()
|
||||||
assert result.equals(c2)
|
assert result.equals(c2)
|
||||||
c1 = math.complex(-1,-2)
|
c1 = cmath.complex(-1,-2)
|
||||||
c2 = math.complex(1,2)
|
c2 = cmath.complex(1,2)
|
||||||
result = c1.addinv()
|
result = c1.addinv()
|
||||||
assert result.equals(c2)
|
assert result.equals(c2)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_complex_mulinv() {
|
fn test_complex_mulinv() {
|
||||||
// Tests were also verified on Wolfram Alpha
|
// Tests were also verified on Wolfram Alpha
|
||||||
mut c1 := math.complex(5,7)
|
mut c1 := cmath.complex(5,7)
|
||||||
mut c2 := math.complex(0.067568,-0.094595)
|
mut c2 := cmath.complex(0.067568,-0.094595)
|
||||||
mut result := c1.mulinv()
|
mut result := c1.mulinv()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-3,4)
|
c1 = cmath.complex(-3,4)
|
||||||
c2 = math.complex(-0.12,-0.16)
|
c2 = cmath.complex(-0.12,-0.16)
|
||||||
result = c1.mulinv()
|
result = c1.mulinv()
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-1,-2)
|
c1 = cmath.complex(-1,-2)
|
||||||
c2 = math.complex(-0.2,0.4)
|
c2 = cmath.complex(-0.2,0.4)
|
||||||
result = c1.mulinv()
|
result = c1.mulinv()
|
||||||
assert result.equals(c2)
|
assert result.equals(c2)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_complex_mod() {
|
fn test_complex_mod() {
|
||||||
// Tests were also verified on Wolfram Alpha
|
// Tests were also verified on Wolfram Alpha
|
||||||
mut c1 := math.complex(5,7)
|
mut c1 := cmath.complex(5,7)
|
||||||
mut result := c1.mod()
|
mut result := c1.mod()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq('8.602325')
|
assert result.str().eq('8.602325')
|
||||||
c1 = math.complex(-3,4)
|
c1 = cmath.complex(-3,4)
|
||||||
result = c1.mod()
|
result = c1.mod()
|
||||||
assert result == 5
|
assert result == 5
|
||||||
c1 = math.complex(-1,-2)
|
c1 = cmath.complex(-1,-2)
|
||||||
result = c1.mod()
|
result = c1.mod()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq('2.236068')
|
assert result.str().eq('2.236068')
|
||||||
@ -179,18 +180,18 @@ fn test_complex_mod() {
|
|||||||
|
|
||||||
fn test_complex_pow() {
|
fn test_complex_pow() {
|
||||||
// Tests were also verified on Wolfram Alpha
|
// Tests were also verified on Wolfram Alpha
|
||||||
mut c1 := math.complex(5,7)
|
mut c1 := cmath.complex(5,7)
|
||||||
mut c2 := math.complex(-24.0,70.0)
|
mut c2 := cmath.complex(-24.0,70.0)
|
||||||
mut result := c1.pow(2)
|
mut result := c1.pow(2)
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-3,4)
|
c1 = cmath.complex(-3,4)
|
||||||
c2 = math.complex(117,44)
|
c2 = cmath.complex(117,44)
|
||||||
result = c1.pow(3)
|
result = c1.pow(3)
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-1,-2)
|
c1 = cmath.complex(-1,-2)
|
||||||
c2 = math.complex(-7,-24)
|
c2 = cmath.complex(-7,-24)
|
||||||
result = c1.pow(4)
|
result = c1.pow(4)
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
@ -198,18 +199,18 @@ fn test_complex_pow() {
|
|||||||
|
|
||||||
fn test_complex_root() {
|
fn test_complex_root() {
|
||||||
// Tests were also verified on Wolfram Alpha
|
// Tests were also verified on Wolfram Alpha
|
||||||
mut c1 := math.complex(5,7)
|
mut c1 := cmath.complex(5,7)
|
||||||
mut c2 := math.complex(2.607904,1.342074)
|
mut c2 := cmath.complex(2.607904,1.342074)
|
||||||
mut result := c1.root(2)
|
mut result := c1.root(2)
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-3,4)
|
c1 = cmath.complex(-3,4)
|
||||||
c2 = math.complex(1.264953,1.150614)
|
c2 = cmath.complex(1.264953,1.150614)
|
||||||
result = c1.root(3)
|
result = c1.root(3)
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-1,-2)
|
c1 = cmath.complex(-1,-2)
|
||||||
c2 = math.complex(1.068059,-0.595482)
|
c2 = cmath.complex(1.068059,-0.595482)
|
||||||
result = c1.root(4)
|
result = c1.root(4)
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
@ -217,18 +218,18 @@ fn test_complex_root() {
|
|||||||
|
|
||||||
fn test_complex_exp() {
|
fn test_complex_exp() {
|
||||||
// Tests were also verified on Wolfram Alpha
|
// Tests were also verified on Wolfram Alpha
|
||||||
mut c1 := math.complex(5,7)
|
mut c1 := cmath.complex(5,7)
|
||||||
mut c2 := math.complex(111.889015,97.505457)
|
mut c2 := cmath.complex(111.889015,97.505457)
|
||||||
mut result := c1.exp()
|
mut result := c1.exp()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-3,4)
|
c1 = cmath.complex(-3,4)
|
||||||
c2 = math.complex(-0.032543,-0.037679)
|
c2 = cmath.complex(-0.032543,-0.037679)
|
||||||
result = c1.exp()
|
result = c1.exp()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-1,-2)
|
c1 = cmath.complex(-1,-2)
|
||||||
c2 = math.complex(-0.153092,-0.334512)
|
c2 = cmath.complex(-0.153092,-0.334512)
|
||||||
result = c1.exp()
|
result = c1.exp()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
@ -236,18 +237,18 @@ fn test_complex_exp() {
|
|||||||
|
|
||||||
fn test_complex_ln() {
|
fn test_complex_ln() {
|
||||||
// Tests were also verified on Wolfram Alpha
|
// Tests were also verified on Wolfram Alpha
|
||||||
mut c1 := math.complex(5,7)
|
mut c1 := cmath.complex(5,7)
|
||||||
mut c2 := math.complex(2.152033,0.950547)
|
mut c2 := cmath.complex(2.152033,0.950547)
|
||||||
mut result := c1.ln()
|
mut result := c1.ln()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-3,4)
|
c1 = cmath.complex(-3,4)
|
||||||
c2 = math.complex(1.609438,2.214297)
|
c2 = cmath.complex(1.609438,2.214297)
|
||||||
result = c1.ln()
|
result = c1.ln()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-1,-2)
|
c1 = cmath.complex(-1,-2)
|
||||||
c2 = math.complex(0.804719,-2.034444)
|
c2 = cmath.complex(0.804719,-2.034444)
|
||||||
result = c1.ln()
|
result = c1.ln()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
@ -255,18 +256,18 @@ fn test_complex_ln() {
|
|||||||
|
|
||||||
fn test_complex_sin() {
|
fn test_complex_sin() {
|
||||||
// Tests were also verified on Wolfram Alpha
|
// Tests were also verified on Wolfram Alpha
|
||||||
mut c1 := math.complex(5,7)
|
mut c1 := cmath.complex(5,7)
|
||||||
mut c2 := math.complex(-525.794515,155.536550)
|
mut c2 := cmath.complex(-525.794515,155.536550)
|
||||||
mut result := c1.sin()
|
mut result := c1.sin()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-3,4)
|
c1 = cmath.complex(-3,4)
|
||||||
c2 = math.complex(-3.853738,-27.016813)
|
c2 = cmath.complex(-3.853738,-27.016813)
|
||||||
result = c1.sin()
|
result = c1.sin()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-1,-2)
|
c1 = cmath.complex(-1,-2)
|
||||||
c2 = math.complex(-3.165779,-1.959601)
|
c2 = cmath.complex(-3.165779,-1.959601)
|
||||||
result = c1.sin()
|
result = c1.sin()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
@ -274,18 +275,18 @@ fn test_complex_sin() {
|
|||||||
|
|
||||||
fn test_complex_cos() {
|
fn test_complex_cos() {
|
||||||
// Tests were also verified on Wolfram Alpha
|
// Tests were also verified on Wolfram Alpha
|
||||||
mut c1 := math.complex(5,7)
|
mut c1 := cmath.complex(5,7)
|
||||||
mut c2 := math.complex(155.536809,525.793641)
|
mut c2 := cmath.complex(155.536809,525.793641)
|
||||||
mut result := c1.cos()
|
mut result := c1.cos()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-3,4)
|
c1 = cmath.complex(-3,4)
|
||||||
c2 = math.complex(-27.034946,3.851153)
|
c2 = cmath.complex(-27.034946,3.851153)
|
||||||
result = c1.cos()
|
result = c1.cos()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-1,-2)
|
c1 = cmath.complex(-1,-2)
|
||||||
c2 = math.complex(2.032723,-3.051898)
|
c2 = cmath.complex(2.032723,-3.051898)
|
||||||
result = c1.cos()
|
result = c1.cos()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
@ -293,18 +294,18 @@ fn test_complex_cos() {
|
|||||||
|
|
||||||
fn test_complex_tan() {
|
fn test_complex_tan() {
|
||||||
// Tests were also verified on Wolfram Alpha
|
// Tests were also verified on Wolfram Alpha
|
||||||
mut c1 := math.complex(5,7)
|
mut c1 := cmath.complex(5,7)
|
||||||
mut c2 := math.complex(-0.000001,1.000001)
|
mut c2 := cmath.complex(-0.000001,1.000001)
|
||||||
mut result := c1.tan()
|
mut result := c1.tan()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-3,4)
|
c1 = cmath.complex(-3,4)
|
||||||
c2 = math.complex(0.000187,0.999356)
|
c2 = cmath.complex(0.000187,0.999356)
|
||||||
result = c1.tan()
|
result = c1.tan()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-1,-2)
|
c1 = cmath.complex(-1,-2)
|
||||||
c2 = math.complex(-0.033813,-1.014794)
|
c2 = cmath.complex(-0.033813,-1.014794)
|
||||||
result = c1.tan()
|
result = c1.tan()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
@ -312,18 +313,18 @@ fn test_complex_tan() {
|
|||||||
|
|
||||||
fn test_complex_sinh() {
|
fn test_complex_sinh() {
|
||||||
// Tests were also verified on Wolfram Alpha
|
// Tests were also verified on Wolfram Alpha
|
||||||
mut c1 := math.complex(5,7)
|
mut c1 := cmath.complex(5,7)
|
||||||
mut c2 := math.complex(55.941968,48.754942)
|
mut c2 := cmath.complex(55.941968,48.754942)
|
||||||
mut result := c1.sinh()
|
mut result := c1.sinh()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-3,4)
|
c1 = cmath.complex(-3,4)
|
||||||
c2 = math.complex(6.548120,-7.619232)
|
c2 = cmath.complex(6.548120,-7.619232)
|
||||||
result = c1.sinh()
|
result = c1.sinh()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-1,-2)
|
c1 = cmath.complex(-1,-2)
|
||||||
c2 = math.complex(0.489056,-1.403119)
|
c2 = cmath.complex(0.489056,-1.403119)
|
||||||
result = c1.sinh()
|
result = c1.sinh()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
@ -331,18 +332,18 @@ fn test_complex_sinh() {
|
|||||||
|
|
||||||
fn test_complex_cosh() {
|
fn test_complex_cosh() {
|
||||||
// Tests were also verified on Wolfram Alpha
|
// Tests were also verified on Wolfram Alpha
|
||||||
mut c1 := math.complex(5,7)
|
mut c1 := cmath.complex(5,7)
|
||||||
mut c2 := math.complex(55.947047,48.750515)
|
mut c2 := cmath.complex(55.947047,48.750515)
|
||||||
mut result := c1.cosh()
|
mut result := c1.cosh()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-3,4)
|
c1 = cmath.complex(-3,4)
|
||||||
c2 = math.complex(-6.580663,7.581553)
|
c2 = cmath.complex(-6.580663,7.581553)
|
||||||
result = c1.cosh()
|
result = c1.cosh()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-1,-2)
|
c1 = cmath.complex(-1,-2)
|
||||||
c2 = math.complex(-0.642148,1.068607)
|
c2 = cmath.complex(-0.642148,1.068607)
|
||||||
result = c1.cosh()
|
result = c1.cosh()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
@ -350,19 +351,21 @@ fn test_complex_cosh() {
|
|||||||
|
|
||||||
fn test_complex_tanh() {
|
fn test_complex_tanh() {
|
||||||
// Tests were also verified on Wolfram Alpha
|
// Tests were also verified on Wolfram Alpha
|
||||||
mut c1 := math.complex(5,7)
|
mut c1 := cmath.complex(5,7)
|
||||||
mut c2 := math.complex(0.999988,0.000090)
|
mut c2 := cmath.complex(0.999988,0.000090)
|
||||||
mut result := c1.tanh()
|
mut result := c1.tanh()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-3,4)
|
c1 = cmath.complex(-3,4)
|
||||||
c2 = math.complex(-1.000710,0.004908)
|
c2 = cmath.complex(-1.000710,0.004908)
|
||||||
result = c1.tanh()
|
result = c1.tanh()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
c1 = math.complex(-1,-2)
|
c1 = cmath.complex(-1,-2)
|
||||||
c2 = math.complex(-1.166736,0.243458)
|
c2 = cmath.complex(-1.166736,0.243458)
|
||||||
result = c1.tanh()
|
result = c1.tanh()
|
||||||
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
// Some issue with precision comparison in f64 using == operator hence serializing to string
|
||||||
assert result.str().eq(c2.str())
|
assert result.str().eq(c2.str())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user