mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-21 04:13:46 +00:00
extras/complex_numbers/*: Add an Mmakefile to build the complex number library, using the new support for user-defined libraries. Move the test cases into a new subdirectory `tests'. Add a new subdirectory `samples', containing an example module `fft.m' that uses the library. Add a README file. extras/complex_numbers/complex.m: Add new functions `complex/1' (converts float to complex), `cis' (cos + i * sin), and `conj'. Rename `norm' as `abs2' (square of absolute value).
55 lines
2.1 KiB
Plaintext
55 lines
2.1 KiB
Plaintext
tests of (complex op complex)
|
|
X = cmplx(3.00000000000000, 4.00000000000000)
|
|
X + X = cmplx(6.00000000000000, 8.00000000000000)
|
|
X - X = cmplx(0.00000000000000, 0.00000000000000)
|
|
X * X = cmplx(-7.00000000000000, 24.0000000000000)
|
|
X / X = cmplx(1.00000000000000, 0.00000000000000)
|
|
Y = cmplx(-5.00000000000000, 6.00000000000000)
|
|
Y + Y = cmplx(-10.0000000000000, 12.0000000000000)
|
|
Y - Y = cmplx(0.00000000000000, 0.00000000000000)
|
|
Y * Y = cmplx(-11.0000000000000, -60.0000000000000)
|
|
Y / Y = cmplx(1.00000000000000, 0.00000000000000)
|
|
X + Y = cmplx(-2.00000000000000, 10.0000000000000)
|
|
X - Y = cmplx(8.00000000000000, -2.00000000000000)
|
|
X * Y = cmplx(-39.0000000000000, -2.00000000000000)
|
|
X / Y = cmplx(0.147540983606557, -0.622950819672131)
|
|
|
|
tests of (imag op imag)
|
|
Z = im(4.00000000000000)
|
|
Z + Z = im(8.00000000000000)
|
|
Z - Z = im(0.00000000000000)
|
|
Z * Z = -16.0000000000000
|
|
Z / Z = 1.00000000000000
|
|
|
|
tests of (float op imag)
|
|
5.0 + Z = cmplx(5.00000000000000, 4.00000000000000)
|
|
5.0 - Z = cmplx(5.00000000000000, -4.00000000000000)
|
|
5.0 * Z = im(20.0000000000000)
|
|
5.0 / Z = im(-1.25000000000000)
|
|
|
|
tests of (imag op float)
|
|
Z + 5.0 = cmplx(5.00000000000000, 4.00000000000000)
|
|
Z - 5.0 = cmplx(-5.00000000000000, 4.00000000000000)
|
|
Z * 5.0 = im(20.0000000000000)
|
|
Z / 5.0 = im(0.800000000000000)
|
|
|
|
tests of (complex op imag)
|
|
X + Z = cmplx(3.00000000000000, 8.00000000000000)
|
|
X - Z = cmplx(3.00000000000000, 0.00000000000000)
|
|
X * Z = cmplx(-16.0000000000000, 12.0000000000000)
|
|
X / Z = cmplx(1.00000000000000, -0.750000000000000)
|
|
Y + Z = cmplx(-5.00000000000000, 10.0000000000000)
|
|
Y - Z = cmplx(-5.00000000000000, 2.00000000000000)
|
|
Y * Z = cmplx(-24.0000000000000, -20.0000000000000)
|
|
Y / Z = cmplx(1.50000000000000, 1.25000000000000)
|
|
|
|
tests of (imag op complex)
|
|
Z + X = cmplx(3.00000000000000, 8.00000000000000)
|
|
Z - X = cmplx(-3.00000000000000, 0.00000000000000)
|
|
Z * X = cmplx(-16.0000000000000, 12.0000000000000)
|
|
Z / X = cmplx(0.640000000000000, 0.480000000000000)
|
|
Z + Y = cmplx(-5.00000000000000, 10.0000000000000)
|
|
Z - Y = cmplx(5.00000000000000, -2.00000000000000)
|
|
Z * Y = cmplx(-24.0000000000000, -20.0000000000000)
|
|
Z / Y = cmplx(0.393442622950820, -0.327868852459016)
|