diff --git a/lib/node_modules/@stdlib/complex/float64/base/div/README.md b/lib/node_modules/@stdlib/complex/float64/base/div/README.md index 103bcadcd00f..3f6f24dcaff6 100644 --- a/lib/node_modules/@stdlib/complex/float64/base/div/README.md +++ b/lib/node_modules/@stdlib/complex/float64/base/div/README.md @@ -50,6 +50,61 @@ var v = cdiv( z1, z2 ); // returns [ 5.0, 3.0 ] ``` +#### cdiv.assign( re1, im1, re2, im2, out, strideOut, offsetOut ) + +Divides two double-precision complex floating-point numbers and assigns results to a provided output array. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var out = new Float64Array( 2 ); +var v = cdiv.assign( -13.0, -1.0, -2.0, 1.0, out, 1, 0 ); +// returns [ 5.0, 3.0 ] + +var bool = ( out === v ); +// returns true +``` + +The function supports the following parameters: + +- **re1**: real component of the first complex number. +- **im1**: imaginary component of the first complex number. +- **re2**: real component of the second complex number. +- **im2**: imaginary component of the second complex number. +- **out**: output array. +- **strideOut**: stride length for `out`. +- **offsetOut**: starting index for `out`. + +#### cdiv.strided( z1, sz1, oz1, z2, sz2, oz2, out, so, oo ) + +Divides two double-precision complex floating-point numbers stored in real-valued strided array views and assigns results to a provided strided output array. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var z1 = new Float64Array( [ -13.0, -1.0 ] ); +var z2 = new Float64Array( [ -2.0, 1.0 ] ); +var out = new Float64Array( 2 ); + +var v = cdiv.strided( z1, 1, 0, z2, 1, 0, out, 1, 0 ); +// returns [ 5.0, 3.0 ] + +var bool = ( out === v ); +// returns true +``` + +The function supports the following parameters: + +- **z1**: first complex number strided array view. +- **sz1**: stride length for `z1`. +- **oz1**: starting index for `z1`. +- **z2**: second complex number strided array view. +- **sz2**: stride length for `z2`. +- **oz2**: starting index for `z2`. +- **out**: output array. +- **so**: stride length for `out`. +- **oo**: starting index for `out`. + diff --git a/lib/node_modules/@stdlib/complex/float64/base/div/benchmark/benchmark.assign.js b/lib/node_modules/@stdlib/complex/float64/base/div/benchmark/benchmark.assign.js new file mode 100644 index 000000000000..b4ee0278b93e --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float64/base/div/benchmark/benchmark.assign.js @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var pkg = require( './../package.json' ).name; +var cdiv = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// MAIN // + +bench( pkg+':assign', function benchmark( b ) { + var out; + var re; + var im; + var N; + var i; + var j; + var k; + + N = 100; + re = uniform( N, -500.0, 500.0, options ); + im = uniform( N, -500.0, 500.0, options ); + + out = new Float64Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + j = i % N; + k = ( i+1 ) % N; + out = cdiv.assign( re[ j ], im[ j ], re[ k ], im[ k ], out, 1, 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( isnan( out[ 0 ] ) || isnan( out[ 1 ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/complex/float64/base/div/benchmark/benchmark.strided.js b/lib/node_modules/@stdlib/complex/float64/base/div/benchmark/benchmark.strided.js new file mode 100644 index 000000000000..0d0986539d5c --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float64/base/div/benchmark/benchmark.strided.js @@ -0,0 +1,68 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var pkg = require( './../package.json' ).name; +var cdiv = require( './../lib' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// MAIN // + +bench( pkg+':strided', function benchmark( b ) { + var out; + var z1; + var z2; + var N; + var i; + var j; + + N = 50; + z1 = uniform( N*2, -500.0, 500.0, options ); + z2 = uniform( N*2, -500.0, 500.0, options ); + + out = new Float64Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + j = ( i % N ) * 2; + out = cdiv.strided( z1, 1, j, z2, 1, j, out, 1, 0 ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( isnan( out[ 0 ] ) || isnan( out[ 1 ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/complex/float64/base/div/docs/repl.txt b/lib/node_modules/@stdlib/complex/float64/base/div/docs/repl.txt index a88ceeb48073..b68fa0236257 100644 --- a/lib/node_modules/@stdlib/complex/float64/base/div/docs/repl.txt +++ b/lib/node_modules/@stdlib/complex/float64/base/div/docs/repl.txt @@ -28,6 +28,92 @@ > var im = {{alias:@stdlib/complex/float64/imag}}( y ) 3.0 - See Also + +{{alias}}.assign( re1, im1, re2, im2, out, strideOut, offsetOut ) + Divides two double-precision complex floating-point numbers and assigns + results to a provided output array. + + Parameters + ---------- + re1: number + Real component of the first complex number. + + im1: number + Imaginary component of the first complex number. + + re2: number + Real component of the second complex number. + + im2: number + Imaginary component of the second complex number. + + out: ArrayLikeObject + Output array. + + strideOut: integer + Stride length. + + offsetOut: integer + Starting index. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples -------- + > var out = new {{alias:@stdlib/array/float64}}( 2 ); + > {{alias}}.assign( -13.0, -1.0, -2.0, 1.0, out, 1, 0 ) + [ 5.0, 3.0 ] + +{{alias}}.strided( z1, sz1, oz1, z2, sz2, oz2, out, so, oo ) + Divides two double-precision complex floating-point numbers stored in real- + valued strided array views and assigns results to a provided strided output + array. + + Parameters + ---------- + z1: ArrayLikeObject + First complex number view. + + sz1: integer + Stride length for `z1`. + + oz1: integer + Starting index for `z1`. + + z2: ArrayLikeObject + Second complex number view. + + sz2: integer + Stride length for `z2`. + + oz2: integer + Starting index for `z2`. + + out: ArrayLikeObject + Output array. + + so: integer + Stride length for `out`. + + oo: integer + Starting index for `out`. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + > var z1 = new {{alias:@stdlib/array/float64}}( [ -13.0, -1.0 ] ); + > var z2 = new {{alias:@stdlib/array/float64}}( [ -2.0, 1.0 ] ); + > var out = new {{alias:@stdlib/array/float64}}( 2 ); + > {{alias}}.strided( z1, 1, 0, z2, 1, 0, out, 1, 0 ) + [ 5.0, 3.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/complex/float64/base/div/docs/types/index.d.ts b/lib/node_modules/@stdlib/complex/float64/base/div/docs/types/index.d.ts index 8a8288be921d..917112995bec 100644 --- a/lib/node_modules/@stdlib/complex/float64/base/div/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/complex/float64/base/div/docs/types/index.d.ts @@ -21,6 +21,79 @@ /// import { Complex128 } from '@stdlib/types/complex'; +import { Collection, NumericArray } from '@stdlib/types/array'; + +/** +* Interface for dividing two double-precision complex floating-point numbers. +*/ +interface Cdiv { + /** + * Divides two double-precision complex floating-point numbers. + * + * @param z1 - complex number + * @param z2 - complex number + * @returns result + * + * @example + * var Complex128 = require( '@stdlib/complex/float64/ctor' ); + * + * var z1 = new Complex128( -13.0, -1.0 ); + * var z2 = new Complex128( -2.0, 1.0 ); + * + * var out = cdiv( z1, z2 ); + * // returns [ 5.0, 3.0 ] + */ + ( z1: Complex128, z2: Complex128 ): Complex128; + + /** + * Divides two double-precision complex floating-point numbers and assigns results to a provided output array. + * + * @param re1 - real component of the first complex number + * @param im1 - imaginary component of the first complex number + * @param re2 - real component of the second complex number + * @param im2 - imaginary component of the second complex number + * @param out - output array + * @param strideOut - stride length + * @param offsetOut - starting index + * @returns output array + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var out = new Float64Array( 2 ); + * var v = cdiv.assign( -13.0, -1.0, -2.0, 1.0, out, 1, 0 ); + * // returns [ 5.0, 3.0 ] + * + * var bool = ( out === v ); + * // returns true + */ + assign>( re1: number, im1: number, re2: number, im2: number, out: T, strideOut: number, offsetOut: number ): T; + + /** + * Divides two double-precision complex floating-point numbers stored in real-valued strided array views and assigns results to a provided strided output array. + * + * @param z1 - first complex number view + * @param strideZ1 - stride length for `z1` + * @param offsetZ1 - starting index for `z1` + * @param z2 - second complex number view + * @param strideZ2 - stride length for `z2` + * @param offsetZ2 - starting index for `z2` + * @param out - output array + * @param strideOut - stride length for `out` + * @param offsetOut - starting index for `out` + * @returns output array + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var z1 = new Float64Array( [ -13.0, -1.0 ] ); + * var z2 = new Float64Array( [ -2.0, 1.0 ] ); + * + * var out = cdiv.strided( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + * // returns [ 5.0, 3.0 ] + */ + strided, U extends NumericArray | Collection, V extends NumericArray | Collection>( z1: T, strideZ1: number, offsetZ1: number, z2: U, strideZ2: number, offsetZ2: number, out: V, strideOut: number, offsetOut: number ): V; +} /** * Divides two double-precision complex floating-point numbers. @@ -38,7 +111,7 @@ import { Complex128 } from '@stdlib/types/complex'; * var out = cdiv( z1, z2 ); * // returns [ 5.0, 3.0 ] */ -declare function cdiv( z1: Complex128, z2: Complex128 ): Complex128; +declare var cdiv: Cdiv; // EXPORTS // diff --git a/lib/node_modules/@stdlib/complex/float64/base/div/docs/types/test.ts b/lib/node_modules/@stdlib/complex/float64/base/div/docs/types/test.ts index 553830349d1d..8b847be7960f 100644 --- a/lib/node_modules/@stdlib/complex/float64/base/div/docs/types/test.ts +++ b/lib/node_modules/@stdlib/complex/float64/base/div/docs/types/test.ts @@ -65,3 +65,293 @@ import cdiv = require( './index' ); cdiv( z ); // $ExpectError cdiv( z, z, z ); // $ExpectError } + +// Attached to the main export is an `assign` method which returns a collection... +{ + cdiv.assign( 1.0, 1.0, 1.0, 1.0, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array + cdiv.assign( 1.0, 1.0, 1.0, 1.0, new Float32Array( 2 ), 1, 0 ); // $ExpectType Float32Array + cdiv.assign( 1.0, 1.0, 1.0, 1.0, [ 0.0, 0.0 ], 1, 0 ); // $ExpectType number[] +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not a number... +{ + const out = new Float64Array( 2 ); + + cdiv.assign( true, 2.0, 3.0, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( false, 2.0, 3.0, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( null, 2.0, 3.0, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( undefined, 2.0, 3.0, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( '5', 2.0, 3.0, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( [], 2.0, 3.0, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( {}, 2.0, 3.0, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( ( x: number ): number => x, 2.0, 3.0, 4.0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not a number... +{ + const out = new Float64Array( 2 ); + + cdiv.assign( 1.0, true, 3.0, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, false, 3.0, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, null, 3.0, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, undefined, 3.0, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, '5', 3.0, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, [], 3.0, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, {}, 3.0, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, ( x: number ): number => x, 3.0, 4.0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a third argument which is not a number... +{ + const out = new Float64Array( 2 ); + + cdiv.assign( 1.0, 2.0, true, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, false, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, null, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, undefined, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, '5', 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, [], 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, {}, 4.0, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, ( x: number ): number => x, 4.0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number... +{ + const out = new Float64Array( 2 ); + + cdiv.assign( 1.0, 2.0, 3.0, true, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, false, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, null, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, undefined, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, '5', out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, [], out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, {}, out, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fifth argument which is not a collection... +{ + cdiv.assign( 1.0, 2.0, 3.0, 4.0, 1, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, true, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, false, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, null, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, undefined, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, '5', 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, [ '5' ], 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, {}, 1, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a sixth argument which is not a number... +{ + const out = new Float64Array( 2 ); + + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out, true, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out, false, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out, null, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out, undefined, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out, '5', 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out, [], 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out, {}, 0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a seventh argument which is not a number... +{ + const out = new Float64Array( 2 ); + + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out, 1, true ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out, 1, false ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out, 1, null ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out, 1, undefined ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out, 1, '5' ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out, 1, [] ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out, 1, {} ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + const out = new Float64Array( 2 ); + + cdiv.assign(); // $ExpectError + cdiv.assign( 1.0 ); // $ExpectError + cdiv.assign( 1.0, 2.0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out, 1 ); // $ExpectError + cdiv.assign( 1.0, 2.0, 3.0, 4.0, out, 1, 0, {} ); // $ExpectError +} + +// Attached to the main export is a `strided` method which returns a collection... +{ + const z1 = new Float64Array( 2 ); + const z2 = new Float64Array( z1.length ); + + cdiv.strided( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); // $ExpectType Float64Array + cdiv.strided( z1, 1, 0, z2, 1, 0, new Float32Array( 2 ), 1, 0 ); // $ExpectType Float32Array + cdiv.strided( z1, 1, 0, z2, 1, 0, [ 0.0, 0.0 ], 1, 0 ); // $ExpectType number[] +} + +// The compiler throws an error if the `strided` method is provided a first argument which is not a collection... +{ + const z1 = new Float64Array( 2 ); + const z2 = new Float64Array( z1.length ); + const out = new Float64Array( z2.length ); + + cdiv.strided( true, 1, 0, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( false, 1, 0, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( null, 1, 0, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( undefined, 1, 0, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( '5', 1, 0, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( [ '5' ], 1, 0, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( {}, 1, 0, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( ( x: number ): number => x, 1, 0, z2, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a second argument which is not a number... +{ + const z1 = new Float64Array( 2 ); + const z2 = new Float64Array( z1.length ); + const out = new Float64Array( z2.length ); + + cdiv.strided( z1, true, 0, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, false, 0, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, null, 0, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, undefined, 0, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, '5', 0, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, [], 0, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, {}, 0, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, ( x: number ): number => x, 0, z2, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a third argument which is not a number... +{ + const z1 = new Float64Array( 2 ); + const z2 = new Float64Array( z1.length ); + const out = new Float64Array( 2 ); + + cdiv.strided( z1, 1, true, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, false, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, null, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, undefined, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, '5', z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, [], z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, {}, z2, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, ( x: number ): number => x, z2, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a fourth argument which is not a collection... +{ + const z1 = new Float64Array( 2 ); + const z2 = new Float64Array( z1.length ); + const out = new Float64Array( z2.length ); + + cdiv.strided( z1, 1, 0, true, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, false, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, null, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, undefined, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, '5', 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, [ '5' ], 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, {}, 1, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, ( x: number ): number => x, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a fifth argument which is not a number... +{ + const z1 = new Float64Array( 2 ); + const z2 = new Float64Array( z1.length ); + const out = new Float64Array( z2.length ); + + cdiv.strided( z1, 1, 0, z2, true, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, false, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, null, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, undefined, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, '5', 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, [], 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, {}, 0, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, ( x: number ): number => x, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a sixth argument which is not a number... +{ + const z1 = new Float64Array( 2 ); + const z2 = new Float64Array( z1.length ); + const out = new Float64Array( z2.length ); + + cdiv.strided( z1, 1, 0, z2, 1, true, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, false, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, null, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, undefined, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, '5', out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, [], out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, {}, out, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a seventh argument which is not a collection... +{ + const z1 = new Float64Array( 2 ); + const z2 = new Float64Array( z1.length ); + + cdiv.strided( z1, 1, 0, z2, 1, 0, 1, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, true, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, false, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, null, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, undefined, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, '5', 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, [ '5' ], 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, {}, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided an eighth argument which is not a number... +{ + const z1 = new Float64Array( 2 ); + const z2 = new Float64Array( z1.length ); + const out = new Float64Array( z2.length ); + + cdiv.strided( z1, 1, 0, z2, 1, 0, out, true, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, out, false, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, out, null, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, out, undefined, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, out, '5', 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, out, [], 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, out, {}, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided a ninth argument which is not a number... +{ + const z1 = new Float64Array( 2 ); + const z2 = new Float64Array( z1.length ); + const out = new Float64Array( z2.length ); + + cdiv.strided( z1, 1, 0, z2, 1, 0, out, 1, true ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, out, 1, false ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, out, 1, null ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, out, 1, undefined ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, out, 1, '5' ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, out, 1, [] ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, out, 1, {} ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `strided` method is provided an unsupported number of arguments... +{ + const z1 = new Float64Array( 2 ); + const z2 = new Float64Array( z1.length ); + const out = new Float64Array( z2.length ); + + cdiv.strided(); // $ExpectError + cdiv.strided( z1 ); // $ExpectError + cdiv.strided( z1, 1 ); // $ExpectError + cdiv.strided( z1, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, out ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, out, 1 ); // $ExpectError + cdiv.strided( z1, 1, 0, z2, 1, 0, out, 1, 0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/complex/float64/base/div/lib/assign.js b/lib/node_modules/@stdlib/complex/float64/base/div/lib/assign.js new file mode 100644 index 000000000000..2d776283f220 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float64/base/div/lib/assign.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var abs = require( '@stdlib/math/base/special/abs' ); +var max = require( '@stdlib/math/base/special/max' ); +var FLOAT64_BIGGEST = require( '@stdlib/constants/float64/max' ); +var FLOAT64_SMALLEST = require( '@stdlib/constants/float64/smallest-normal' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var robustInternal = require( './robust_internal.js' ); + + +// VARIABLES // + +var LARGE_THRESHOLD = FLOAT64_BIGGEST * 0.5; +var SMALL_THRESHOLD = FLOAT64_SMALLEST * ( 2.0 / EPS ); +var RECIP_EPS_SQR = 2.0 / ( EPS * EPS ); + + +// MAIN // + +/** +* Divides two double-precision complex floating-point numbers and assigns results to a provided output array. +* +* @param {number} re1 - real component of the first complex number +* @param {number} im1 - imaginary component of the first complex number +* @param {number} re2 - real component of the second complex number +* @param {number} im2 - imaginary component of the second complex number +* @param {Collection} out - output array +* @param {integer} strideOut - stride length +* @param {NonNegativeInteger} offsetOut - starting index +* @returns {Collection} output array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var out = assign( -13.0, -1.0, -2.0, 1.0, new Float64Array( 2 ), 1, 0 ); +* // returns [ 5.0, 3.0 ] +*/ +function assign( re1, im1, re2, im2, out, strideOut, offsetOut ) { + var res; + var ab; + var cd; + var s; + + ab = max( abs(re1), abs(im1) ); + cd = max( abs(re2), abs(im2) ); + s = 1.0; + + if ( ab >= LARGE_THRESHOLD ) { + re1 *= 0.5; + im1 *= 0.5; + s *= 2.0; + } else if ( ab <= SMALL_THRESHOLD ) { + re1 *= RECIP_EPS_SQR; + im1 *= RECIP_EPS_SQR; + s /= RECIP_EPS_SQR; + } + if ( cd >= LARGE_THRESHOLD ) { + re2 *= 0.5; + im2 *= 0.5; + s *= 0.5; + } else if ( cd <= SMALL_THRESHOLD ) { + re2 *= RECIP_EPS_SQR; + im2 *= RECIP_EPS_SQR; + s *= RECIP_EPS_SQR; + } + + if ( abs( im2 ) <= abs( re2 ) ) { + res = robustInternal( re1, im1, re2, im2 ); + } else { + res = robustInternal( im1, re1, im2, re2 ); + res[ 1 ] *= -1.0; + } + + res[ 0 ] *= s; + res[ 1 ] *= s; + + out[ offsetOut ] = res[ 0 ]; + out[ offsetOut+strideOut ] = res[ 1 ]; + + return out; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/complex/float64/base/div/lib/index.js b/lib/node_modules/@stdlib/complex/float64/base/div/lib/index.js index e597396483f7..9b4d9ad9832c 100644 --- a/lib/node_modules/@stdlib/complex/float64/base/div/lib/index.js +++ b/lib/node_modules/@stdlib/complex/float64/base/div/lib/index.js @@ -36,9 +36,20 @@ // MODULES // +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); var main = require( './main.js' ); +var assign = require( './assign.js' ); +var strided = require( './strided.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); +setReadOnly( main, 'strided', strided ); // EXPORTS // module.exports = main; + +// exports: { "assign": "main.assign", "strided": "main.strided" } diff --git a/lib/node_modules/@stdlib/complex/float64/base/div/lib/main.js b/lib/node_modules/@stdlib/complex/float64/base/div/lib/main.js index f18aa2211300..252df9190150 100644 --- a/lib/node_modules/@stdlib/complex/float64/base/div/lib/main.js +++ b/lib/node_modules/@stdlib/complex/float64/base/div/lib/main.js @@ -20,22 +20,16 @@ // MODULES // -var abs = require( '@stdlib/math/base/special/abs' ); -var max = require( '@stdlib/math/base/special/max' ); -var FLOAT64_BIGGEST = require( '@stdlib/constants/float64/max' ); -var FLOAT64_SMALLEST = require( '@stdlib/constants/float64/smallest-normal' ); -var EPS = require( '@stdlib/constants/float64/eps' ); var real = require( '@stdlib/complex/float64/real' ); var imag = require( '@stdlib/complex/float64/imag' ); +var Float64Array = require( '@stdlib/array/float64' ); var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var robustInternal = require( './robust_internal.js' ); +var assign = require( './assign.js' ); // VARIABLES // -var LARGE_THRESHOLD = FLOAT64_BIGGEST * 0.5; -var SMALL_THRESHOLD = FLOAT64_SMALLEST * ( 2.0 / EPS ); -var RECIP_EPS_SQR = 2.0 / ( EPS * EPS ); +var out = new Float64Array( 2 ); // MAIN // @@ -65,46 +59,14 @@ function cdiv( z1, z2 ) { var re2; var im1; var im2; - var out; - var ab; - var cd; - var s; re1 = real( z1 ); re2 = real( z2 ); im1 = imag( z1 ); im2 = imag( z2 ); - ab = max( abs(re1), abs(im1) ); - cd = max( abs(re2), abs(im2) ); - s = 1.0; + out = assign( re1, im1, re2, im2, out, 1, 0 ); - if ( ab >= LARGE_THRESHOLD ) { - re1 *= 0.5; - im1 *= 0.5; - s *= 2.0; - } else if ( ab <= SMALL_THRESHOLD ) { - re1 *= RECIP_EPS_SQR; - im1 *= RECIP_EPS_SQR; - s /= RECIP_EPS_SQR; - } - if ( cd >= LARGE_THRESHOLD ) { - re2 *= 0.5; - im2 *= 0.5; - s *= 0.5; - } else if ( cd <= SMALL_THRESHOLD ) { - re2 *= RECIP_EPS_SQR; - im2 *= RECIP_EPS_SQR; - s *= RECIP_EPS_SQR; - } - if ( abs( im2 ) <= abs( re2 ) ) { - out = robustInternal( re1, im1, re2, im2 ); - } else { - out = robustInternal( im1, re1, im2, re2 ); - out[ 1 ] *= -1.0; - } - out[ 0 ] *= s; - out[ 1 ] *= s; return new Complex128( out[ 0 ], out[ 1 ] ); } diff --git a/lib/node_modules/@stdlib/complex/float64/base/div/lib/strided.js b/lib/node_modules/@stdlib/complex/float64/base/div/lib/strided.js new file mode 100644 index 000000000000..d5f0f36ec602 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float64/base/div/lib/strided.js @@ -0,0 +1,58 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var assign = require( './assign.js' ); + + +// MAIN // + +/** +* Divides two double-precision complex floating-point numbers stored in real-valued strided array views and assigns results to a provided strided output array. +* +* @param {Float64Array} z1 - first complex number view +* @param {integer} strideZ1 - stride length for `z1` +* @param {NonNegativeInteger} offsetZ1 - starting index for `z1` +* @param {Float64Array} z2 - second complex number view +* @param {integer} strideZ2 - stride length for `z2` +* @param {NonNegativeInteger} offsetZ2 - starting index for `z2` +* @param {Collection} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` +* @returns {Collection} output array +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var z1 = new Float64Array( [ -13.0, -1.0 ] ); +* var z2 = new Float64Array( [ -2.0, 1.0 ] ); +* +* var out = strided( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); +* // returns [ 5.0, 3.0 ] +*/ +function strided( z1, strideZ1, offsetZ1, z2, strideZ2, offsetZ2, out, strideOut, offsetOut ) { // eslint-disable-line max-len + return assign( z1[ offsetZ1 ], z1[ offsetZ1+strideZ1 ], z2[ offsetZ2 ], z2[ offsetZ2+strideZ2 ], out, strideOut, offsetOut ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = strided; diff --git a/lib/node_modules/@stdlib/complex/float64/base/div/test/test.assign.js b/lib/node_modules/@stdlib/complex/float64/base/div/test/test.assign.js new file mode 100644 index 000000000000..26b9a0f98745 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float64/base/div/test/test.assign.js @@ -0,0 +1,967 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable id-length */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isAlmostEqualFloat64Array = require( '@stdlib/assert/is-almost-equal-float64array' ); +var toBinaryString = require( '@stdlib/number/float64/base/to-binary-string' ); +var Float64Array = require( '@stdlib/array/float64' ); +var cdiv = require( './../lib/assign.js' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); +var componentScales1 = require( './fixtures/julia/component_scales1.json' ); +var componentScales2 = require( './fixtures/julia/component_scales2.json' ); +var imaginaryComponentScales = require( './fixtures/julia/imaginary_component_scales.json' ); +var realComponentScales = require( './fixtures/julia/real_component_scales.json' ); +var largeNegativeImaginaryComponents = require( './fixtures/julia/large_negative_imaginary_components.json' ); +var largeNegativeRealComponents = require( './fixtures/julia/large_negative_real_components.json' ); +var largePositiveImaginaryComponents = require( './fixtures/julia/large_positive_imaginary_components.json' ); +var largePositiveRealComponents = require( './fixtures/julia/large_positive_real_components.json' ); +var tinyNegativeImaginaryComponents = require( './fixtures/julia/tiny_negative_imaginary_components.json' ); +var tinyNegativeRealComponents = require( './fixtures/julia/tiny_negative_real_components.json' ); +var tinyPositiveImaginaryComponents = require( './fixtures/julia/tiny_positive_imaginary_components.json' ); +var tinyPositiveRealComponents = require( './fixtures/julia/tiny_positive_real_components.json' ); + + +// FUNCTIONS // + +/** +* Compares the binary representations of two double-precision floating-point numbers and returns the first index of a differing bit. If all bits match, the function returns `-1`. +* +* TODO: revisit once ULP distance fcn is written +* +* @private +* @param {number} a - first number +* @param {number} b - second number +* @returns {integer} index +*/ +function bitdiff( a, b ) { + var astr; + var bstr; + var i; + + astr = toBinaryString( a ); + bstr = toBinaryString( b ); + for ( i = 0; i < 64; i++ ) { + if ( astr[ i ] !== bstr[ i ] ) { + return i; + } + } + return -1; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cdiv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function computes a complex quotient (base behavior)', function test( t ) { + var expected; + var out; + var v; + + out = new Float64Array( 2 ); + + v = cdiv( 2.0, 4.0, 1.0, 2.0, out, 1, 0 ); + expected = new Float64Array( [ 2.0, 0.0 ] ); + + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + t.end(); +}); + +tape( 'the function computes a complex quotient (difficult cases)', function test( t ) { + var idx; + var re1; + var im1; + var re2; + var im2; + var out; + var v; + + // Note: test cases extracted from Figure 6 of https://arxiv.org/pdf/1210.4539.pdf. + + // Test case #1: + out = new Float64Array( 2 ); + v = cdiv( 1.0, 1.0, 1.0, pow( 2.0, 1023.0 ), out, 1, 0 ); + + idx = bitdiff( v[ 0 ], pow( 2.0, -1023.0 ) ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( v[ 1 ], -pow( 2.0, -1023.0 ) ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #2: + out = new Float64Array( 2 ); + v = cdiv( 1.0, 1.0, pow( 2.0, -1023.0 ), pow( 2.0, -1023.0 ), out, 1, 0 ); + + idx = bitdiff( v[ 0 ], pow( 2.0, 1023.0 ) ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( v[ 1 ], 0.0 ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #3: + re1 = pow( 2.0, 1023.0 ); + im1 = pow( 2.0, -1023.0 ); + re2 = pow( 2.0, 677.0 ); + im2 = pow( 2.0, -677.0 ); + + out = new Float64Array( 2 ); + v = cdiv( re1, im1, re2, im2, out, 1, 0 ); + + idx = bitdiff( v[ 0 ], pow( 2.0, 346.0 ) ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( v[ 1 ], -pow( 2.0, -1008.0 ) ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #4: + out = new Float64Array( 2 ); + v = cdiv( pow( 2.0, 1023.0 ), pow( 2.0, 1023.0 ), 1.0, 1.0, out, 1, 0 ); + + idx = bitdiff( v[ 0 ], pow( 2.0, 1023.0 ) ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( v[ 1 ], 0.0 ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #5: + re1 = pow( 2.0, 1020.0 ); + im1 = pow( 2.0, -844.0 ); + re2 = pow( 2.0, 656.0 ); + im2 = pow( 2.0, -780.0 ); + + out = new Float64Array( 2 ); + v = cdiv( re1, im1, re2, im2, out, 1, 0 ); + + idx = bitdiff( v[ 0 ], pow( 2.0, 364.0 ) ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( v[ 1 ], -pow( 2.0, -1072.0 ) ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #6: + re1 = pow( 2.0, -71.0 ); + im1 = pow( 2.0, 1021.0 ); + re2 = pow( 2.0, 1001.0 ); + im2 = pow( 2.0, -323.0 ); + + out = new Float64Array( 2 ); + v = cdiv( re1, im1, re2, im2, out, 1, 0 ); + + idx = bitdiff( v[ 0 ], pow( 2.0, -1072.0 ) ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( v[ 1 ], pow( 2.0, 20.0 ) ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #7: + re1 = pow( 2.0, -347.0 ); + im1 = pow( 2.0, -54.0 ); + re2 = pow( 2.0, -1037.0 ); + im2 = pow( 2.0, -1058.0 ); + + out = new Float64Array( 2 ); + v = cdiv( re1, im1, re2, im2, out, 1, 0 ); + + idx = bitdiff( v[ 0 ], 3.898125604559113300e289 ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( v[ 1 ], 8.174961907852353577e295 ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #8: + re1 = pow( 2.0, -1074.0 ); + im1 = pow( 2.0, -1074.0 ); + re2 = pow( 2.0, -1073.0 ); + im2 = pow( 2.0, -1074.0 ); + + out = new Float64Array( 2 ); + v = cdiv( re1, im1, re2, im2, out, 1, 0 ); + + /* + * See section 3.6 in https://arxiv.org/pdf/1210.4539.pdf. + * + * ```text + * real(q): 0011111111100011001100110011001100110011001100110011001100110100 + * 0.6: 0011111111100011001100110011001100110011001100110011001100110011 + * ``` + * + * If we add + * + * ```text + * 0000000000000000000000000000000000000000000000000000000000000001 + * ``` + * + * to `0.6`, we get `real( q )`; thus, the result is 1 bit off. + */ + idx = bitdiff( v[ 0 ], 0.6 ); + t.strictEqual( idx, 61, 'real component has expected binary representation' ); + + idx = bitdiff( v[ 1 ], 0.2 ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #9: + re1 = pow( 2.0, 1015.0 ); + im1 = pow( 2.0, -989.0 ); + re2 = pow( 2.0, 1023.0 ); + im2 = pow( 2.0, 1023.0 ); + + out = new Float64Array( 2 ); + v = cdiv( re1, im1, re2, im2, out, 1, 0 ); + + idx = bitdiff( v[ 0 ], 0.001953125 ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( v[ 1 ], -0.001953125 ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #10: + re1 = pow( 2.0, -622.0 ); + im1 = pow( 2.0, -1071.0 ); + re2 = pow( 2.0, -343.0 ); + im2 = pow( 2.0, -798.0 ); + + out = new Float64Array( 2 ); + v = cdiv( re1, im1, re2, im2, out, 1, 0 ); + + idx = bitdiff( v[ 0 ], 1.02951151789360578e-84 ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( v[ 1 ], 6.97145987515076231e-220 ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + t.end(); +}); + +tape( 'the function computes a complex quotient (tested against fixtures)', function test( t ) { + var delta; + var out; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var i; + var q; + + re1 = data.re1; + im1 = data.im1; + re2 = data.re2; + im2 = data.im2; + qre = data.qre; + qim = data.qim; + out = new Float64Array( 2 ); + + for ( i = 0; i < re1.length; i++ ) { + q = cdiv( re1[ i ], im1[ i ], re2[ i ], im2[ i ], out, 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[ 0 ]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[ 1 ]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (different component scales)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var out; + var i; + var q; + + re1 = componentScales1.re1; + im1 = componentScales1.im1; + re2 = componentScales1.re2; + im2 = componentScales1.im2; + qre = componentScales1.qre; + qim = componentScales1.qim; + out = new Float64Array( 2 ); + + for ( i = 0; i < re1.length; i++ ) { + q = cdiv( re1[ i ], im1[ i ], re2[ i ], im2[ i ], out, 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[ 0 ]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[ 1 ]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (different component scales)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var out; + var i; + var q; + + re1 = componentScales2.re1; + im1 = componentScales2.im1; + re2 = componentScales2.re2; + im2 = componentScales2.im2; + qre = componentScales2.qre; + qim = componentScales2.qim; + out = new Float64Array( 2 ); + + for ( i = 0; i < re1.length; i++ ) { + q = cdiv( re1[ i ], im1[ i ], re2[ i ], im2[ i ], out, 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[ 0 ]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[ 1 ]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (different imaginary component scales)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var out; + var i; + var q; + + re1 = imaginaryComponentScales.re1; + im1 = imaginaryComponentScales.im1; + re2 = imaginaryComponentScales.re2; + im2 = imaginaryComponentScales.im2; + qre = imaginaryComponentScales.qre; + qim = imaginaryComponentScales.qim; + out = new Float64Array( 2 ); + + for ( i = 0; i < re1.length; i++ ) { + q = cdiv( re1[ i ], im1[ i ], re2[ i ], im2[ i ], out, 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[ 0 ]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[ 1 ]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (real imaginary component scales)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var out; + var i; + var q; + + re1 = realComponentScales.re1; + im1 = realComponentScales.im1; + re2 = realComponentScales.re2; + im2 = realComponentScales.im2; + qre = realComponentScales.qre; + qim = realComponentScales.qim; + out = new Float64Array( 2 ); + + for ( i = 0; i < re1.length; i++ ) { + q = cdiv( re1[ i ], im1[ i ], re2[ i ], im2[ i ], out, 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[ 0 ]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[ 1 ]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (large negative imaginary components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var out; + var i; + var q; + + re1 = largeNegativeImaginaryComponents.re1; + im1 = largeNegativeImaginaryComponents.im1; + re2 = largeNegativeImaginaryComponents.re2; + im2 = largeNegativeImaginaryComponents.im2; + qre = largeNegativeImaginaryComponents.qre; + qim = largeNegativeImaginaryComponents.qim; + out = new Float64Array( 2 ); + + for ( i = 0; i < re1.length; i++ ) { + q = cdiv( re1[ i ], im1[ i ], re2[ i ], im2[ i ], out, 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[ 0 ]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[ 1 ]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (large negative real components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var out; + var i; + var q; + + re1 = largeNegativeRealComponents.re1; + im1 = largeNegativeRealComponents.im1; + re2 = largeNegativeRealComponents.re2; + im2 = largeNegativeRealComponents.im2; + qre = largeNegativeRealComponents.qre; + qim = largeNegativeRealComponents.qim; + out = new Float64Array( 2 ); + + for ( i = 0; i < re1.length; i++ ) { + q = cdiv( re1[ i ], im1[ i ], re2[ i ], im2[ i ], out, 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[ 0 ]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[ 1 ]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (large positive imaginary components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var out; + var i; + var q; + + re1 = largePositiveImaginaryComponents.re1; + im1 = largePositiveImaginaryComponents.im1; + re2 = largePositiveImaginaryComponents.re2; + im2 = largePositiveImaginaryComponents.im2; + qre = largePositiveImaginaryComponents.qre; + qim = largePositiveImaginaryComponents.qim; + out = new Float64Array( 2 ); + + for ( i = 0; i < re1.length; i++ ) { + q = cdiv( re1[ i ], im1[ i ], re2[ i ], im2[ i ], out, 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[ 0 ]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[ 1 ]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (large positive real components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var out; + var i; + var q; + + re1 = largePositiveRealComponents.re1; + im1 = largePositiveRealComponents.im1; + re2 = largePositiveRealComponents.re2; + im2 = largePositiveRealComponents.im2; + qre = largePositiveRealComponents.qre; + qim = largePositiveRealComponents.qim; + out = new Float64Array( 2 ); + + for ( i = 0; i < re1.length; i++ ) { + q = cdiv( re1[ i ], im1[ i ], re2[ i ], im2[ i ], out, 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[ 0 ]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[ 1 ]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (tiny negative imaginary components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var out; + var i; + var q; + + re1 = tinyNegativeImaginaryComponents.re1; + im1 = tinyNegativeImaginaryComponents.im1; + re2 = tinyNegativeImaginaryComponents.re2; + im2 = tinyNegativeImaginaryComponents.im2; + qre = tinyNegativeImaginaryComponents.qre; + qim = tinyNegativeImaginaryComponents.qim; + out = new Float64Array( 2 ); + + for ( i = 0; i < re1.length; i++ ) { + q = cdiv( re1[ i ], im1[ i ], re2[ i ], im2[ i ], out, 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[ 0 ]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[ 1 ]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (tiny negative real components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var out; + var i; + var q; + + re1 = tinyNegativeRealComponents.re1; + im1 = tinyNegativeRealComponents.im1; + re2 = tinyNegativeRealComponents.re2; + im2 = tinyNegativeRealComponents.im2; + qre = tinyNegativeRealComponents.qre; + qim = tinyNegativeRealComponents.qim; + out = new Float64Array( 2 ); + + for ( i = 0; i < re1.length; i++ ) { + q = cdiv( re1[ i ], im1[ i ], re2[ i ], im2[ i ], out, 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[ 0 ]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[ 1 ]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (tiny positive imaginary components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var out; + var i; + var q; + + re1 = tinyPositiveImaginaryComponents.re1; + im1 = tinyPositiveImaginaryComponents.im1; + re2 = tinyPositiveImaginaryComponents.re2; + im2 = tinyPositiveImaginaryComponents.im2; + qre = tinyPositiveImaginaryComponents.qre; + qim = tinyPositiveImaginaryComponents.qim; + out = new Float64Array( 2 ); + + for ( i = 0; i < re1.length; i++ ) { + q = cdiv( re1[ i ], im1[ i ], re2[ i ], im2[ i ], out, 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[ 0 ]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[ 1 ]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (tiny positive real components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var out; + var qim; + var i; + var q; + + re1 = tinyPositiveRealComponents.re1; + im1 = tinyPositiveRealComponents.im1; + re2 = tinyPositiveRealComponents.re2; + im2 = tinyPositiveRealComponents.im2; + qre = tinyPositiveRealComponents.qre; + qim = tinyPositiveRealComponents.qim; + out = new Float64Array( 2 ); + + for ( i = 0; i < re1.length; i++ ) { + q = cdiv( re1[ i ], im1[ i ], re2[ i ], im2[ i ], out, 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[ 0 ]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[ 1 ]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function handles large and small numbers', function test( t ) { + var expected; + var out; + var v; + + out = new Float64Array( 2 ); + v = cdiv( 1.0e308, 5.0e307, 1.0, 0.5, out, 1, 0 ); + expected = new Float64Array( [ 1.0e308, 0.0 ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( 1.0, 0.5, 1.0e308, 5.0e307, out, 1, 0 ); + expected = new Float64Array( [ 1.0e-308, 0.0 ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( 1.0e-304, 2.0e-304, 1.0, 2.0, out, 1, 0 ); + expected = new Float64Array( [ 1.0e-304, 0.0 ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( 1.0, 2.0, 1.0e-304, 2.0e-304, out, 1, 0 ); + expected = new Float64Array( [ 1.0e+304, 0.0 ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( 2.0, 4.0, 0.0, 2.0, out, 1, 0 ); + expected = new Float64Array( [ 2.0, -1.0 ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( 1.0e-180, 1.0e-180, 1.0, 1.0e-180, out, 1, 0 ); + expected = new Float64Array( [ 1.0e-180, 1.0e-180 ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + t.end(); +}); + +tape( 'the function may overflow during complex division', function test( t ) { + var expected; + var out; + var v; + + out = new Float64Array( 2 ); + v = cdiv( 1.0e308, 1.0e308, 5.0e-324, 5.0e-324, out, 1, 0 ); + expected = new Float64Array( [ PINF, 0.0 ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( 1.0e308, 1.0e308, -5.0e-324, 5.0e-324, out, 1, 0 ); + expected = new Float64Array( [ 0.0, NINF ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( 1.0e308, -1.0e308, 5.0e-324, 5.0e-324, out, 1, 0 ); + expected = new Float64Array( [ 0.0, NINF ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( -1.0e308, 1.0e308, 5.0e-324, 5.0e-324, out, 1, 0 ); + expected = new Float64Array( [ 0.0, PINF ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( 1.0e308, 1.0e308, 5.0e-324, -5.0e-324, out, 1, 0 ); + expected = new Float64Array( [ 0.0, PINF ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( -1.0e308, 1.0e308, -5.0e-324, 5.0e-324, out, 1, 0 ); + expected = new Float64Array( [ PINF, 0.0 ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( 1.0e308, -1.0e308, 5.0e-324, -5.0e-324, out, 1, 0 ); + expected = new Float64Array( [ PINF, 0.0 ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( 1.0e308, -1.0e308, -5.0e-324, 5.0e-324, out, 1, 0 ); + expected = new Float64Array( [ NINF, 0.0 ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( -1.0e308, 1.0e308, 5.0e-324, -5.0e-324, out, 1, 0 ); + expected = new Float64Array( [ NINF, 0.0 ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( -1.0e308, -1.0e308, -5.0e-324, 5.0e-324, out, 1, 0 ); + expected = new Float64Array( [ 0.0, PINF ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( 1.0e308, -1.0e308, -5.0e-324, -5.0e-324, out, 1, 0 ); + expected = new Float64Array( [ 0.0, PINF ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( -1.0e308, 1.0e308, -5.0e-324, -5.0e-324, out, 1, 0 ); + expected = new Float64Array( [ 0.0, NINF ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( -1.0e308, -1.0e308, 5.0e-324, -5.0e-324, out, 1, 0 ); + expected = new Float64Array( [ 0.0, NINF ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + t.end(); +}); + +tape( 'if a real or imaginary component is `NaN`, all components are `NaN`', function test( t ) { + var out; + var v; + + out = new Float64Array( 2 ); + v = cdiv( NaN, 3.0, -2.0, 1.0, out, 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns expected values' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( 5.0, NaN, -2.0, 1.0, out, 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns expected values' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( 5.0, 3.0, NaN, 1.0, out, 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns expected values' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( 5.0, 3.0, -2.0, NaN, out, 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns expected values' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( 5.0, 3.0, NaN, NaN, out, 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns expected values' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( NaN, NaN, -2.0, 1.0, out, 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns expected values' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns expected values' ); + + out = new Float64Array( 2 ); + v = cdiv( NaN, NaN, NaN, NaN, out, 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns expected values' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns expected values' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/complex/float64/base/div/test/test.js b/lib/node_modules/@stdlib/complex/float64/base/div/test/test.js index fd158ba25f29..20cb9b7412b4 100644 --- a/lib/node_modules/@stdlib/complex/float64/base/div/test/test.js +++ b/lib/node_modules/@stdlib/complex/float64/base/div/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,1042 +16,31 @@ * limitations under the License. */ -/* eslint-disable id-length */ - 'use strict'; // MODULES // var tape = require( 'tape' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var abs = require( '@stdlib/math/base/special/abs' ); -var pow = require( '@stdlib/math/base/special/pow' ); -var EPS = require( '@stdlib/constants/float64/eps' ); -var PINF = require( '@stdlib/constants/float64/pinf' ); -var NINF = require( '@stdlib/constants/float64/ninf' ); -var toBinaryString = require( '@stdlib/number/float64/base/to-binary-string' ); -var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var real = require( '@stdlib/complex/float64/real' ); -var imag = require( '@stdlib/complex/float64/imag' ); -var cdiv = require( './../lib' ); - - -// FIXTURES // - -var data = require( './fixtures/julia/data.json' ); -var componentScales1 = require( './fixtures/julia/component_scales1.json' ); -var componentScales2 = require( './fixtures/julia/component_scales2.json' ); -var imaginaryComponentScales = require( './fixtures/julia/imaginary_component_scales.json' ); -var realComponentScales = require( './fixtures/julia/real_component_scales.json' ); -var largeNegativeImaginaryComponents = require( './fixtures/julia/large_negative_imaginary_components.json' ); -var largeNegativeRealComponents = require( './fixtures/julia/large_negative_real_components.json' ); -var largePositiveImaginaryComponents = require( './fixtures/julia/large_positive_imaginary_components.json' ); -var largePositiveRealComponents = require( './fixtures/julia/large_positive_real_components.json' ); -var tinyNegativeImaginaryComponents = require( './fixtures/julia/tiny_negative_imaginary_components.json' ); -var tinyNegativeRealComponents = require( './fixtures/julia/tiny_negative_real_components.json' ); -var tinyPositiveImaginaryComponents = require( './fixtures/julia/tiny_positive_imaginary_components.json' ); -var tinyPositiveRealComponents = require( './fixtures/julia/tiny_positive_real_components.json' ); - - -// FUNCTIONS // - -/** -* Compares the binary representations of two double-precision floating-point numbers and returns the first index of a differing bit. If all bits match, the function returns `-1`. -* -* TODO: revisit once ULP distance fcn is written -* -* @private -* @param {number} a - first number -* @param {number} b - second number -* @returns {integer} index -*/ -function bitdiff( a, b ) { - var astr; - var bstr; - var i; - - astr = toBinaryString( a ); - bstr = toBinaryString( b ); - for ( i = 0; i < 64; i++ ) { - if ( astr[ i ] !== bstr[ i ] ) { - return i; - } - } - return -1; -} +var isMethod = require( '@stdlib/assert/is-method' ); +var div = require( './../lib' ); // TESTS // tape( 'main export is a function', function test( t ) { t.ok( true, __filename ); - t.strictEqual( typeof cdiv, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function computes a complex quotient (base behavior)', function test( t ) { - var z1; - var z2; - var v; - - z1 = new Complex128( 2.0, 4.0 ); - z2 = new Complex128( 1.0, 2.0 ); - - v = cdiv( z1, z2 ); - - t.strictEqual( real( v ), 2.0, 'returns expected value' ); - t.strictEqual( imag( v ), 0.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function computes a complex quotient (difficult cases)', function test( t ) { - var idx; - var re1; - var im1; - var re2; - var im2; - var z1; - var z2; - var q; - - // Note: test cases extracted from Figure 6 of https://arxiv.org/pdf/1210.4539.pdf. - - // Test case #1: - z1 = new Complex128( 1.0, 1.0 ); - z2 = new Complex128( 1.0, pow( 2.0, 1023.0 ) ); - - q = cdiv( z1, z2 ); - - idx = bitdiff( real( q ), pow( 2.0, -1023.0 ) ); - t.strictEqual( idx, -1, 'real component has expected binary representation' ); - - idx = bitdiff( imag( q ), -pow( 2.0, -1023.0 ) ); - t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); - - // Test case #2: - z1 = new Complex128( 1.0, 1.0 ); - z2 = new Complex128( pow( 2.0, -1023.0 ), pow( 2.0, -1023.0 ) ); - - q = cdiv( z1, z2 ); - - idx = bitdiff( real( q ), pow( 2.0, 1023.0 ) ); - t.strictEqual( idx, -1, 'real component has expected binary representation' ); - - idx = bitdiff( imag( q ), 0.0 ); - t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); - - // Test case #3: - re1 = pow( 2.0, 1023.0 ); - im1 = pow( 2.0, -1023.0 ); - re2 = pow( 2.0, 677.0 ); - im2 = pow( 2.0, -677.0 ); - - z1 = new Complex128( re1, im1 ); - z2 = new Complex128( re2, im2 ); - - q = cdiv( z1, z2 ); - - idx = bitdiff( real( q ), pow( 2.0, 346.0 ) ); - t.strictEqual( idx, -1, 'real component has expected binary representation' ); - - idx = bitdiff( imag( q ), -pow( 2.0, -1008.0 ) ); - t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); - - // Test case #4: - z1 = new Complex128( pow( 2.0, 1023.0 ), pow( 2.0, 1023.0 ) ); - z2 = new Complex128( 1.0, 1.0 ); - - q = cdiv( z1, z2 ); - - idx = bitdiff( real( q ), pow( 2.0, 1023.0 ) ); - t.strictEqual( idx, -1, 'real component has expected binary representation' ); - - idx = bitdiff( imag( q ), 0.0 ); - t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); - - // Test case #5: - re1 = pow( 2.0, 1020.0 ); - im1 = pow( 2.0, -844.0 ); - re2 = pow( 2.0, 656.0 ); - im2 = pow( 2.0, -780.0 ); - - z1 = new Complex128( re1, im1 ); - z2 = new Complex128( re2, im2 ); - - q = cdiv( z1, z2 ); - - idx = bitdiff( real( q ), pow( 2.0, 364.0 ) ); - t.strictEqual( idx, -1, 'real component has expected binary representation' ); - - idx = bitdiff( imag( q ), -pow( 2.0, -1072.0 ) ); - t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); - - // Test case #6: - re1 = pow( 2.0, -71.0 ); - im1 = pow( 2.0, 1021.0 ); - re2 = pow( 2.0, 1001.0 ); - im2 = pow( 2.0, -323.0 ); - - z1 = new Complex128( re1, im1 ); - z2 = new Complex128( re2, im2 ); - - q = cdiv( z1, z2 ); - - idx = bitdiff( real( q ), pow( 2.0, -1072.0 ) ); - t.strictEqual( idx, -1, 'real component has expected binary representation' ); - - idx = bitdiff( imag( q ), pow( 2.0, 20.0 ) ); - t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); - - // Test case #7: - re1 = pow( 2.0, -347.0 ); - im1 = pow( 2.0, -54.0 ); - re2 = pow( 2.0, -1037.0 ); - im2 = pow( 2.0, -1058.0 ); - - z1 = new Complex128( re1, im1 ); - z2 = new Complex128( re2, im2 ); - - q = cdiv( z1, z2 ); - - idx = bitdiff( real( q ), 3.898125604559113300e289 ); - t.strictEqual( idx, -1, 'real component has expected binary representation' ); - - idx = bitdiff( imag( q ), 8.174961907852353577e295 ); - t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); - - // Test case #8: - re1 = pow( 2.0, -1074.0 ); - im1 = pow( 2.0, -1074.0 ); - re2 = pow( 2.0, -1073.0 ); - im2 = pow( 2.0, -1074.0 ); - - z1 = new Complex128( re1, im1 ); - z2 = new Complex128( re2, im2 ); - - q = cdiv( z1, z2 ); - - /* - * See section 3.6 in https://arxiv.org/pdf/1210.4539.pdf. - * - * ```text - * real(q): 0011111111100011001100110011001100110011001100110011001100110100 - * 0.6: 0011111111100011001100110011001100110011001100110011001100110011 - * ``` - * - * If we add - * - * ```text - * 0000000000000000000000000000000000000000000000000000000000000001 - * ``` - * - * to `0.6`, we get `real( q )`; thus, the result is 1 bit off. - */ - idx = bitdiff( real( q ), 0.6 ); - t.strictEqual( idx, 61, 'real component has expected binary representation' ); - - idx = bitdiff( imag( q ), 0.2 ); - t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); - - // Test case #9: - re1 = pow( 2.0, 1015.0 ); - im1 = pow( 2.0, -989.0 ); - re2 = pow( 2.0, 1023.0 ); - im2 = pow( 2.0, 1023.0 ); - - z1 = new Complex128( re1, im1 ); - z2 = new Complex128( re2, im2 ); - - q = cdiv( z1, z2 ); - - idx = bitdiff( real( q ), 0.001953125 ); - t.strictEqual( idx, -1, 'real component has expected binary representation' ); - - idx = bitdiff( imag( q ), -0.001953125 ); - t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); - - // Test case #10: - re1 = pow( 2.0, -622.0 ); - im1 = pow( 2.0, -1071.0 ); - re2 = pow( 2.0, -343.0 ); - im2 = pow( 2.0, -798.0 ); - - z1 = new Complex128( re1, im1 ); - z2 = new Complex128( re2, im2 ); - - q = cdiv( z1, z2 ); - - idx = bitdiff( real( q ), 1.02951151789360578e-84 ); - t.strictEqual( idx, -1, 'real component has expected binary representation' ); - - idx = bitdiff( imag( q ), 6.97145987515076231e-220 ); - t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); - - t.end(); -}); - -tape( 'the function computes a complex quotient (tested against fixtures)', function test( t ) { - var delta; - var tol; - var re1; - var im1; - var re2; - var im2; - var qre; - var qim; - var z1; - var z2; - var i; - var q; - - re1 = data.re1; - im1 = data.im1; - re2 = data.re2; - im2 = data.im2; - qre = data.qre; - qim = data.qim; - - for ( i = 0; i < re1.length; i++ ) { - z1 = new Complex128( re1[ i ], im1[ i ] ); - z2 = new Complex128( re2[ i ], im2[ i ] ); - q = cdiv( z1, z2 ); - - if ( real( q ) === qre[ i ] ) { - t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); - } else { - delta = abs( real( q ) - qre[ i ] ); - tol = EPS * abs( qre[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( imag( q ) === qim[ i ] ) { - t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); - } else { - delta = abs( imag( q ) - qim[ i ] ); - tol = EPS * abs( qim[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } - t.end(); -}); - -tape( 'the function computes a complex quotient (different component scales)', function test( t ) { - var delta; - var tol; - var re1; - var im1; - var re2; - var im2; - var qre; - var qim; - var z1; - var z2; - var i; - var q; - - re1 = componentScales1.re1; - im1 = componentScales1.im1; - re2 = componentScales1.re2; - im2 = componentScales1.im2; - qre = componentScales1.qre; - qim = componentScales1.qim; - - for ( i = 0; i < re1.length; i++ ) { - z1 = new Complex128( re1[ i ], im1[ i ] ); - z2 = new Complex128( re2[ i ], im2[ i ] ); - q = cdiv( z1, z2 ); - - if ( real( q ) === qre[ i ] ) { - t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); - } else { - delta = abs( real( q ) - qre[ i ] ); - tol = EPS * abs( qre[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( imag( q ) === qim[ i ] ) { - t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); - } else { - delta = abs( imag( q ) - qim[ i ] ); - tol = EPS * abs( qim[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } - t.end(); -}); - -tape( 'the function computes a complex quotient (different component scales)', function test( t ) { - var delta; - var tol; - var re1; - var im1; - var re2; - var im2; - var qre; - var qim; - var z1; - var z2; - var i; - var q; - - re1 = componentScales2.re1; - im1 = componentScales2.im1; - re2 = componentScales2.re2; - im2 = componentScales2.im2; - qre = componentScales2.qre; - qim = componentScales2.qim; - - for ( i = 0; i < re1.length; i++ ) { - z1 = new Complex128( re1[ i ], im1[ i ] ); - z2 = new Complex128( re2[ i ], im2[ i ] ); - q = cdiv( z1, z2 ); - - if ( real( q ) === qre[ i ] ) { - t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); - } else { - delta = abs( real( q ) - qre[ i ] ); - tol = EPS * abs( qre[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( imag( q ) === qim[ i ] ) { - t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); - } else { - delta = abs( imag( q ) - qim[ i ] ); - tol = EPS * abs( qim[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } - t.end(); -}); - -tape( 'the function computes a complex quotient (different imaginary component scales)', function test( t ) { - var delta; - var tol; - var re1; - var im1; - var re2; - var im2; - var qre; - var qim; - var z1; - var z2; - var i; - var q; - - re1 = imaginaryComponentScales.re1; - im1 = imaginaryComponentScales.im1; - re2 = imaginaryComponentScales.re2; - im2 = imaginaryComponentScales.im2; - qre = imaginaryComponentScales.qre; - qim = imaginaryComponentScales.qim; - - for ( i = 0; i < re1.length; i++ ) { - z1 = new Complex128( re1[ i ], im1[ i ] ); - z2 = new Complex128( re2[ i ], im2[ i ] ); - q = cdiv( z1, z2 ); - - if ( real( q ) === qre[ i ] ) { - t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); - } else { - delta = abs( real( q ) - qre[ i ] ); - tol = EPS * abs( qre[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( imag( q ) === qim[ i ] ) { - t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); - } else { - delta = abs( imag( q ) - qim[ i ] ); - tol = EPS * abs( qim[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } + t.strictEqual( typeof div, 'function', 'main export is a function' ); t.end(); }); -tape( 'the function computes a complex quotient (real imaginary component scales)', function test( t ) { - var delta; - var tol; - var re1; - var im1; - var re2; - var im2; - var qre; - var qim; - var z1; - var z2; - var i; - var q; - - re1 = realComponentScales.re1; - im1 = realComponentScales.im1; - re2 = realComponentScales.re2; - im2 = realComponentScales.im2; - qre = realComponentScales.qre; - qim = realComponentScales.qim; - - for ( i = 0; i < re1.length; i++ ) { - z1 = new Complex128( re1[ i ], im1[ i ] ); - z2 = new Complex128( re2[ i ], im2[ i ] ); - q = cdiv( z1, z2 ); - - if ( real( q ) === qre[ i ] ) { - t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); - } else { - delta = abs( real( q ) - qre[ i ] ); - tol = EPS * abs( qre[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( imag( q ) === qim[ i ] ) { - t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); - } else { - delta = abs( imag( q ) - qim[ i ] ); - tol = EPS * abs( qim[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } - t.end(); -}); - -tape( 'the function computes a complex quotient (large negative imaginary components)', function test( t ) { - var delta; - var tol; - var re1; - var im1; - var re2; - var im2; - var qre; - var qim; - var z1; - var z2; - var i; - var q; - - re1 = largeNegativeImaginaryComponents.re1; - im1 = largeNegativeImaginaryComponents.im1; - re2 = largeNegativeImaginaryComponents.re2; - im2 = largeNegativeImaginaryComponents.im2; - qre = largeNegativeImaginaryComponents.qre; - qim = largeNegativeImaginaryComponents.qim; - - for ( i = 0; i < re1.length; i++ ) { - z1 = new Complex128( re1[ i ], im1[ i ] ); - z2 = new Complex128( re2[ i ], im2[ i ] ); - q = cdiv( z1, z2 ); - - if ( real( q ) === qre[ i ] ) { - t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); - } else { - delta = abs( real( q ) - qre[ i ] ); - tol = EPS * abs( qre[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( imag( q ) === qim[ i ] ) { - t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); - } else { - delta = abs( imag( q ) - qim[ i ] ); - tol = EPS * abs( qim[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } - t.end(); -}); - -tape( 'the function computes a complex quotient (large negative real components)', function test( t ) { - var delta; - var tol; - var re1; - var im1; - var re2; - var im2; - var qre; - var qim; - var z1; - var z2; - var i; - var q; - - re1 = largeNegativeRealComponents.re1; - im1 = largeNegativeRealComponents.im1; - re2 = largeNegativeRealComponents.re2; - im2 = largeNegativeRealComponents.im2; - qre = largeNegativeRealComponents.qre; - qim = largeNegativeRealComponents.qim; - - for ( i = 0; i < re1.length; i++ ) { - z1 = new Complex128( re1[ i ], im1[ i ] ); - z2 = new Complex128( re2[ i ], im2[ i ] ); - q = cdiv( z1, z2 ); - - if ( real( q ) === qre[ i ] ) { - t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); - } else { - delta = abs( real( q ) - qre[ i ] ); - tol = EPS * abs( qre[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( imag( q ) === qim[ i ] ) { - t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); - } else { - delta = abs( imag( q ) - qim[ i ] ); - tol = EPS * abs( qim[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } - t.end(); -}); - -tape( 'the function computes a complex quotient (large positive imaginary components)', function test( t ) { - var delta; - var tol; - var re1; - var im1; - var re2; - var im2; - var qre; - var qim; - var z1; - var z2; - var i; - var q; - - re1 = largePositiveImaginaryComponents.re1; - im1 = largePositiveImaginaryComponents.im1; - re2 = largePositiveImaginaryComponents.re2; - im2 = largePositiveImaginaryComponents.im2; - qre = largePositiveImaginaryComponents.qre; - qim = largePositiveImaginaryComponents.qim; - - for ( i = 0; i < re1.length; i++ ) { - z1 = new Complex128( re1[ i ], im1[ i ] ); - z2 = new Complex128( re2[ i ], im2[ i ] ); - q = cdiv( z1, z2 ); - - if ( real( q ) === qre[ i ] ) { - t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); - } else { - delta = abs( real( q ) - qre[ i ] ); - tol = EPS * abs( qre[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( imag( q ) === qim[ i ] ) { - t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); - } else { - delta = abs( imag( q ) - qim[ i ] ); - tol = EPS * abs( qim[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } - t.end(); -}); - -tape( 'the function computes a complex quotient (large positive real components)', function test( t ) { - var delta; - var tol; - var re1; - var im1; - var re2; - var im2; - var qre; - var qim; - var z1; - var z2; - var i; - var q; - - re1 = largePositiveRealComponents.re1; - im1 = largePositiveRealComponents.im1; - re2 = largePositiveRealComponents.re2; - im2 = largePositiveRealComponents.im2; - qre = largePositiveRealComponents.qre; - qim = largePositiveRealComponents.qim; - - for ( i = 0; i < re1.length; i++ ) { - z1 = new Complex128( re1[ i ], im1[ i ] ); - z2 = new Complex128( re2[ i ], im2[ i ] ); - q = cdiv( z1, z2 ); - - if ( real( q ) === qre[ i ] ) { - t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); - } else { - delta = abs( real( q ) - qre[ i ] ); - tol = EPS * abs( qre[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( imag( q ) === qim[ i ] ) { - t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); - } else { - delta = abs( imag( q ) - qim[ i ] ); - tol = EPS * abs( qim[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } - t.end(); -}); - -tape( 'the function computes a complex quotient (tiny negative imaginary components)', function test( t ) { - var delta; - var tol; - var re1; - var im1; - var re2; - var im2; - var qre; - var qim; - var z1; - var z2; - var i; - var q; - - re1 = tinyNegativeImaginaryComponents.re1; - im1 = tinyNegativeImaginaryComponents.im1; - re2 = tinyNegativeImaginaryComponents.re2; - im2 = tinyNegativeImaginaryComponents.im2; - qre = tinyNegativeImaginaryComponents.qre; - qim = tinyNegativeImaginaryComponents.qim; - - for ( i = 0; i < re1.length; i++ ) { - z1 = new Complex128( re1[ i ], im1[ i ] ); - z2 = new Complex128( re2[ i ], im2[ i ] ); - q = cdiv( z1, z2 ); - - if ( real( q ) === qre[ i ] ) { - t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); - } else { - delta = abs( real( q ) - qre[ i ] ); - tol = EPS * abs( qre[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( imag( q ) === qim[ i ] ) { - t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); - } else { - delta = abs( imag( q ) - qim[ i ] ); - tol = EPS * abs( qim[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } - t.end(); -}); - -tape( 'the function computes a complex quotient (tiny negative real components)', function test( t ) { - var delta; - var tol; - var re1; - var im1; - var re2; - var im2; - var qre; - var qim; - var z1; - var z2; - var i; - var q; - - re1 = tinyNegativeRealComponents.re1; - im1 = tinyNegativeRealComponents.im1; - re2 = tinyNegativeRealComponents.re2; - im2 = tinyNegativeRealComponents.im2; - qre = tinyNegativeRealComponents.qre; - qim = tinyNegativeRealComponents.qim; - - for ( i = 0; i < re1.length; i++ ) { - z1 = new Complex128( re1[ i ], im1[ i ] ); - z2 = new Complex128( re2[ i ], im2[ i ] ); - q = cdiv( z1, z2 ); - - if ( real( q ) === qre[ i ] ) { - t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); - } else { - delta = abs( real( q ) - qre[ i ] ); - tol = EPS * abs( qre[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( imag( q ) === qim[ i ] ) { - t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); - } else { - delta = abs( imag( q ) - qim[ i ] ); - tol = EPS * abs( qim[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } - t.end(); -}); - -tape( 'the function computes a complex quotient (tiny positive imaginary components)', function test( t ) { - var delta; - var tol; - var re1; - var im1; - var re2; - var im2; - var qre; - var qim; - var z1; - var z2; - var i; - var q; - - re1 = tinyPositiveImaginaryComponents.re1; - im1 = tinyPositiveImaginaryComponents.im1; - re2 = tinyPositiveImaginaryComponents.re2; - im2 = tinyPositiveImaginaryComponents.im2; - qre = tinyPositiveImaginaryComponents.qre; - qim = tinyPositiveImaginaryComponents.qim; - - for ( i = 0; i < re1.length; i++ ) { - z1 = new Complex128( re1[ i ], im1[ i ] ); - z2 = new Complex128( re2[ i ], im2[ i ] ); - q = cdiv( z1, z2 ); - - if ( real( q ) === qre[ i ] ) { - t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); - } else { - delta = abs( real( q ) - qre[ i ] ); - tol = EPS * abs( qre[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( imag( q ) === qim[ i ] ) { - t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); - } else { - delta = abs( imag( q ) - qim[ i ] ); - tol = EPS * abs( qim[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } - t.end(); -}); - -tape( 'the function computes a complex quotient (tiny positive real components)', function test( t ) { - var delta; - var tol; - var re1; - var im1; - var re2; - var im2; - var qre; - var qim; - var z1; - var z2; - var i; - var q; - - re1 = tinyPositiveRealComponents.re1; - im1 = tinyPositiveRealComponents.im1; - re2 = tinyPositiveRealComponents.re2; - im2 = tinyPositiveRealComponents.im2; - qre = tinyPositiveRealComponents.qre; - qim = tinyPositiveRealComponents.qim; - - for ( i = 0; i < re1.length; i++ ) { - z1 = new Complex128( re1[ i ], im1[ i ] ); - z2 = new Complex128( re2[ i ], im2[ i ] ); - q = cdiv( z1, z2 ); - - if ( real( q ) === qre[ i ] ) { - t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); - } else { - delta = abs( real( q ) - qre[ i ] ); - tol = EPS * abs( qre[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - if ( imag( q ) === qim[ i ] ) { - t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); - } else { - delta = abs( imag( q ) - qim[ i ] ); - tol = EPS * abs( qim[ i ] ); - t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); - } - } - t.end(); -}); - -tape( 'the function handles large and small numbers', function test( t ) { - var expected; - var z1; - var z2; - var v; - - z1 = new Complex128( 1.0e308, 5.0e307 ); - z2 = new Complex128( 1.0, 0.5 ); - v = cdiv( z1, z2 ); - expected = [ 1.0e308, 0.0 ]; - - t.strictEqual( real( v ), expected[ 0 ], 'returns expected values' ); - t.strictEqual( imag( v ), expected[ 1 ], 'returns expected values' ); - - z1 = new Complex128( 1.0, 0.5 ); - z2 = new Complex128( 1.0e308, 5.0e307 ); - v = cdiv( z1, z2 ); - expected = [ 1.0e-308, 0.0 ]; - - t.strictEqual( real( v ), expected[ 0 ], 'returns expected values' ); - t.strictEqual( imag( v ), expected[ 1 ], 'returns expected values' ); - - z1 = new Complex128( 1.0e-304, 2.0e-304 ); - z2 = new Complex128( 1.0, 2.0 ); - v = cdiv( z1, z2 ); - expected = [ 1.0e-304, 0.0 ]; - - t.strictEqual( real( v ), expected[ 0 ], 'returns expected values' ); - t.strictEqual( imag( v ), expected[ 1 ], 'returns expected values' ); - - z1 = new Complex128( 1.0, 2.0 ); - z2 = new Complex128( 1.0e-304, 2.0e-304 ); - v = cdiv( z1, z2 ); - expected = [ 1.0e+304, 0.0 ]; - - t.strictEqual( real( v ), expected[ 0 ], 'returns expected values' ); - t.strictEqual( imag( v ), expected[ 1 ], 'returns expected values' ); - - z1 = new Complex128( 2.0, 4.0 ); - z2 = new Complex128( 0.0, 2.0 ); - v = cdiv( z1, z2 ); - expected = [ 2.0, -1.0 ]; - - t.strictEqual( real( v ), expected[ 0 ], 'returns expected values' ); - t.strictEqual( imag( v ), expected[ 1 ], 'returns expected values' ); - - z1 = new Complex128( 1.0e-180, 1.0e-180 ); - z2 = new Complex128( 1.0, 1.0e-180 ); - v = cdiv( z1, z2 ); - expected = [ 1.0e-180, 1.0e-180 ]; - - t.strictEqual( real( v ), expected[ 0 ], 'returns expected values' ); - t.strictEqual( imag( v ), expected[ 1 ], 'returns expected values' ); - - t.end(); -}); - -tape( 'the function may overflow during complex division', function test( t ) { - var z1; - var z2; - var v; - - z1 = new Complex128( 1.0e308, 1.0e308 ); - z2 = new Complex128( 5.0e-324, 5.0e-324 ); - v = cdiv( z1, z2 ); - t.strictEqual( real( v ), PINF, 'real component is +infinity' ); - t.strictEqual( imag( v ), 0.0, 'imaginary component is 0' ); - - z1 = new Complex128( 1.0e308, 1.0e308 ); - z2 = new Complex128( -5.0e-324, 5.0e-324 ); - v = cdiv( z1, z2 ); - t.strictEqual( real( v ), 0.0, 'real component is 0' ); - t.strictEqual( imag( v ), NINF, 'imaginary component is -infinity' ); - - z1 = new Complex128( 1.0e308, -1.0e308 ); - z2 = new Complex128( 5.0e-324, 5.0e-324 ); - v = cdiv( z1, z2 ); - t.strictEqual( real( v ), 0.0, 'real component is 0' ); - t.strictEqual( imag( v ), NINF, 'imaginary component is -infinity' ); - - z1 = new Complex128( -1.0e308, 1.0e308 ); - z2 = new Complex128( 5.0e-324, 5.0e-324 ); - v = cdiv( z1, z2 ); - t.strictEqual( real( v ), 0.0, 'real component is 0' ); - t.strictEqual( imag( v ), PINF, 'imaginary component is +infinity' ); - - z1 = new Complex128( 1.0e308, 1.0e308 ); - z2 = new Complex128( 5.0e-324, -5.0e-324 ); - v = cdiv( z1, z2 ); - t.strictEqual( real( v ), 0.0, 'real component is 0' ); - t.strictEqual( imag( v ), PINF, 'imaginary component is +infinity' ); - - z1 = new Complex128( -1.0e308, 1.0e308 ); - z2 = new Complex128( -5.0e-324, 5.0e-324 ); - v = cdiv( z1, z2 ); - t.strictEqual( real( v ), PINF, 'real component is +infinity' ); - t.strictEqual( imag( v ), 0.0, 'imaginary component is 0' ); - - z1 = new Complex128( 1.0e308, -1.0e308 ); - z2 = new Complex128( 5.0e-324, -5.0e-324 ); - v = cdiv( z1, z2 ); - t.strictEqual( real( v ), PINF, 'real component is +infinity' ); - t.strictEqual( imag( v ), 0.0, 'imaginary component is 0' ); - - z1 = new Complex128( 1.0e308, -1.0e308 ); - z2 = new Complex128( -5.0e-324, 5.0e-324 ); - v = cdiv( z1, z2 ); - t.strictEqual( real( v ), NINF, 'real component is -infinity' ); - t.strictEqual( imag( v ), 0.0, 'imaginary component is 0' ); - - z1 = new Complex128( -1.0e308, 1.0e308 ); - z2 = new Complex128( 5.0e-324, -5.0e-324 ); - v = cdiv( z1, z2 ); - t.strictEqual( real( v ), NINF, 'real component is -infinity' ); - t.strictEqual( imag( v ), 0.0, 'imaginary component is 0' ); - - z1 = new Complex128( -1.0e308, -1.0e308 ); - z2 = new Complex128( -5.0e-324, 5.0e-324 ); - v = cdiv( z1, z2 ); - t.strictEqual( real( v ), 0.0, 'real component is 0' ); - t.strictEqual( imag( v ), PINF, 'imaginary component is +infinity' ); - - z1 = new Complex128( 1.0e308, -1.0e308 ); - z2 = new Complex128( -5.0e-324, -5.0e-324 ); - v = cdiv( z1, z2 ); - t.strictEqual( real( v ), 0.0, 'real component is 0' ); - t.strictEqual( imag( v ), PINF, 'imaginary component is +infinity' ); - - z1 = new Complex128( -1.0e308, 1.0e308 ); - z2 = new Complex128( -5.0e-324, -5.0e-324 ); - v = cdiv( z1, z2 ); - t.strictEqual( real( v ), 0.0, 'real component is 0' ); - t.strictEqual( imag( v ), NINF, 'imaginary component is -infinity' ); - - z1 = new Complex128( -1.0e308, -1.0e308 ); - z2 = new Complex128( 5.0e-324, -5.0e-324 ); - v = cdiv( z1, z2 ); - t.strictEqual( real( v ), 0.0, 'real component is 0' ); - t.strictEqual( imag( v ), NINF, 'imaginary component is -infinity' ); - +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( isMethod( div, 'assign' ), true, 'returns expected value' ); t.end(); }); -tape( 'if a real or imaginary component is `NaN`, all components are `NaN`', function test( t ) { - var z1; - var z2; - var v; - - z1 = new Complex128( NaN, 3.0 ); - z2 = new Complex128( -2.0, 1.0 ); - v = cdiv( z1, z2 ); - t.strictEqual( isnan( real( v ) ), true, 'returns NaN' ); - t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' ); - - z1 = new Complex128( 5.0, NaN ); - z2 = new Complex128( -2.0, 1.0 ); - v = cdiv( z1, z2 ); - t.strictEqual( isnan( real( v ) ), true, 'returns NaN' ); - t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' ); - - z1 = new Complex128( 5.0, 3.0 ); - z2 = new Complex128( NaN, 1.0 ); - v = cdiv( z1, z2 ); - t.strictEqual( isnan( real( v ) ), true, 'returns NaN' ); - t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' ); - - z1 = new Complex128( 5.0, 3.0 ); - z2 = new Complex128( -2.0, NaN ); - v = cdiv( z1, z2 ); - t.strictEqual( isnan( real( v ) ), true, 'returns NaN' ); - t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' ); - - z1 = new Complex128( 5.0, 3.0 ); - z2 = new Complex128( NaN, NaN ); - v = cdiv( z1, z2 ); - t.strictEqual( isnan( real( v ) ), true, 'returns NaN' ); - t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' ); - - z1 = new Complex128( NaN, NaN ); - z2 = new Complex128( -2.0, 1.0 ); - v = cdiv( z1, z2 ); - t.strictEqual( isnan( real( v ) ), true, 'returns NaN' ); - t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' ); - - z1 = new Complex128( NaN, NaN ); - z2 = new Complex128( NaN, NaN ); - v = cdiv( z1, z2 ); - t.strictEqual( isnan( real( v ) ), true, 'returns NaN' ); - t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' ); - +tape( 'attached to the main export is a `strided` method', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( isMethod( div, 'strided' ), true, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/complex/float64/base/div/test/test.main.js b/lib/node_modules/@stdlib/complex/float64/base/div/test/test.main.js new file mode 100644 index 000000000000..4b8c1091b434 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float64/base/div/test/test.main.js @@ -0,0 +1,1057 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable id-length, max-statements */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var toBinaryString = require( '@stdlib/number/float64/base/to-binary-string' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var cdiv = require( './../lib' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); +var componentScales1 = require( './fixtures/julia/component_scales1.json' ); +var componentScales2 = require( './fixtures/julia/component_scales2.json' ); +var imaginaryComponentScales = require( './fixtures/julia/imaginary_component_scales.json' ); +var realComponentScales = require( './fixtures/julia/real_component_scales.json' ); +var largeNegativeImaginaryComponents = require( './fixtures/julia/large_negative_imaginary_components.json' ); +var largeNegativeRealComponents = require( './fixtures/julia/large_negative_real_components.json' ); +var largePositiveImaginaryComponents = require( './fixtures/julia/large_positive_imaginary_components.json' ); +var largePositiveRealComponents = require( './fixtures/julia/large_positive_real_components.json' ); +var tinyNegativeImaginaryComponents = require( './fixtures/julia/tiny_negative_imaginary_components.json' ); +var tinyNegativeRealComponents = require( './fixtures/julia/tiny_negative_real_components.json' ); +var tinyPositiveImaginaryComponents = require( './fixtures/julia/tiny_positive_imaginary_components.json' ); +var tinyPositiveRealComponents = require( './fixtures/julia/tiny_positive_real_components.json' ); + + +// FUNCTIONS // + +/** +* Compares the binary representations of two double-precision floating-point numbers and returns the first index of a differing bit. If all bits match, the function returns `-1`. +* +* TODO: revisit once ULP distance fcn is written +* +* @private +* @param {number} a - first number +* @param {number} b - second number +* @returns {integer} index +*/ +function bitdiff( a, b ) { + var astr; + var bstr; + var i; + + astr = toBinaryString( a ); + bstr = toBinaryString( b ); + for ( i = 0; i < 64; i++ ) { + if ( astr[ i ] !== bstr[ i ] ) { + return i; + } + } + return -1; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cdiv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function computes a complex quotient (base behavior)', function test( t ) { + var z1; + var z2; + var v; + + z1 = new Complex128( 2.0, 4.0 ); + z2 = new Complex128( 1.0, 2.0 ); + + v = cdiv( z1, z2 ); + + t.strictEqual( real( v ), 2.0, 'returns expected value' ); + t.strictEqual( imag( v ), 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes a complex quotient (difficult cases)', function test( t ) { + var idx; + var re1; + var im1; + var re2; + var im2; + var z1; + var z2; + var q; + + // Note: test cases extracted from Figure 6 of https://arxiv.org/pdf/1210.4539.pdf. + + // Test case #1: + z1 = new Complex128( 1.0, 1.0 ); + z2 = new Complex128( 1.0, pow( 2.0, 1023.0 ) ); + + q = cdiv( z1, z2 ); + + idx = bitdiff( real( q ), pow( 2.0, -1023.0 ) ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( imag( q ), -pow( 2.0, -1023.0 ) ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #2: + z1 = new Complex128( 1.0, 1.0 ); + z2 = new Complex128( pow( 2.0, -1023.0 ), pow( 2.0, -1023.0 ) ); + + q = cdiv( z1, z2 ); + + idx = bitdiff( real( q ), pow( 2.0, 1023.0 ) ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( imag( q ), 0.0 ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #3: + re1 = pow( 2.0, 1023.0 ); + im1 = pow( 2.0, -1023.0 ); + re2 = pow( 2.0, 677.0 ); + im2 = pow( 2.0, -677.0 ); + + z1 = new Complex128( re1, im1 ); + z2 = new Complex128( re2, im2 ); + + q = cdiv( z1, z2 ); + + idx = bitdiff( real( q ), pow( 2.0, 346.0 ) ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( imag( q ), -pow( 2.0, -1008.0 ) ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #4: + z1 = new Complex128( pow( 2.0, 1023.0 ), pow( 2.0, 1023.0 ) ); + z2 = new Complex128( 1.0, 1.0 ); + + q = cdiv( z1, z2 ); + + idx = bitdiff( real( q ), pow( 2.0, 1023.0 ) ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( imag( q ), 0.0 ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #5: + re1 = pow( 2.0, 1020.0 ); + im1 = pow( 2.0, -844.0 ); + re2 = pow( 2.0, 656.0 ); + im2 = pow( 2.0, -780.0 ); + + z1 = new Complex128( re1, im1 ); + z2 = new Complex128( re2, im2 ); + + q = cdiv( z1, z2 ); + + idx = bitdiff( real( q ), pow( 2.0, 364.0 ) ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( imag( q ), -pow( 2.0, -1072.0 ) ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #6: + re1 = pow( 2.0, -71.0 ); + im1 = pow( 2.0, 1021.0 ); + re2 = pow( 2.0, 1001.0 ); + im2 = pow( 2.0, -323.0 ); + + z1 = new Complex128( re1, im1 ); + z2 = new Complex128( re2, im2 ); + + q = cdiv( z1, z2 ); + + idx = bitdiff( real( q ), pow( 2.0, -1072.0 ) ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( imag( q ), pow( 2.0, 20.0 ) ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #7: + re1 = pow( 2.0, -347.0 ); + im1 = pow( 2.0, -54.0 ); + re2 = pow( 2.0, -1037.0 ); + im2 = pow( 2.0, -1058.0 ); + + z1 = new Complex128( re1, im1 ); + z2 = new Complex128( re2, im2 ); + + q = cdiv( z1, z2 ); + + idx = bitdiff( real( q ), 3.898125604559113300e289 ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( imag( q ), 8.174961907852353577e295 ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #8: + re1 = pow( 2.0, -1074.0 ); + im1 = pow( 2.0, -1074.0 ); + re2 = pow( 2.0, -1073.0 ); + im2 = pow( 2.0, -1074.0 ); + + z1 = new Complex128( re1, im1 ); + z2 = new Complex128( re2, im2 ); + + q = cdiv( z1, z2 ); + + /* + * See section 3.6 in https://arxiv.org/pdf/1210.4539.pdf. + * + * ```text + * real(q): 0011111111100011001100110011001100110011001100110011001100110100 + * 0.6: 0011111111100011001100110011001100110011001100110011001100110011 + * ``` + * + * If we add + * + * ```text + * 0000000000000000000000000000000000000000000000000000000000000001 + * ``` + * + * to `0.6`, we get `real( q )`; thus, the result is 1 bit off. + */ + idx = bitdiff( real( q ), 0.6 ); + t.strictEqual( idx, 61, 'real component has expected binary representation' ); + + idx = bitdiff( imag( q ), 0.2 ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #9: + re1 = pow( 2.0, 1015.0 ); + im1 = pow( 2.0, -989.0 ); + re2 = pow( 2.0, 1023.0 ); + im2 = pow( 2.0, 1023.0 ); + + z1 = new Complex128( re1, im1 ); + z2 = new Complex128( re2, im2 ); + + q = cdiv( z1, z2 ); + + idx = bitdiff( real( q ), 0.001953125 ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( imag( q ), -0.001953125 ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #10: + re1 = pow( 2.0, -622.0 ); + im1 = pow( 2.0, -1071.0 ); + re2 = pow( 2.0, -343.0 ); + im2 = pow( 2.0, -798.0 ); + + z1 = new Complex128( re1, im1 ); + z2 = new Complex128( re2, im2 ); + + q = cdiv( z1, z2 ); + + idx = bitdiff( real( q ), 1.02951151789360578e-84 ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( imag( q ), 6.97145987515076231e-220 ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + t.end(); +}); + +tape( 'the function computes a complex quotient (tested against fixtures)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = data.re1; + im1 = data.im1; + re2 = data.re2; + im2 = data.im2; + qre = data.qre; + qim = data.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Complex128( re1[ i ], im1[ i ] ); + z2 = new Complex128( re2[ i ], im2[ i ] ); + q = cdiv( z1, z2 ); + + if ( real( q ) === qre[ i ] ) { + t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); + } else { + delta = abs( real( q ) - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( imag( q ) === qim[ i ] ) { + t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( imag( q ) - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (different component scales)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = componentScales1.re1; + im1 = componentScales1.im1; + re2 = componentScales1.re2; + im2 = componentScales1.im2; + qre = componentScales1.qre; + qim = componentScales1.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Complex128( re1[ i ], im1[ i ] ); + z2 = new Complex128( re2[ i ], im2[ i ] ); + q = cdiv( z1, z2 ); + + if ( real( q ) === qre[ i ] ) { + t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); + } else { + delta = abs( real( q ) - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( imag( q ) === qim[ i ] ) { + t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( imag( q ) - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (different component scales)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = componentScales2.re1; + im1 = componentScales2.im1; + re2 = componentScales2.re2; + im2 = componentScales2.im2; + qre = componentScales2.qre; + qim = componentScales2.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Complex128( re1[ i ], im1[ i ] ); + z2 = new Complex128( re2[ i ], im2[ i ] ); + q = cdiv( z1, z2 ); + + if ( real( q ) === qre[ i ] ) { + t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); + } else { + delta = abs( real( q ) - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( imag( q ) === qim[ i ] ) { + t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( imag( q ) - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (different imaginary component scales)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = imaginaryComponentScales.re1; + im1 = imaginaryComponentScales.im1; + re2 = imaginaryComponentScales.re2; + im2 = imaginaryComponentScales.im2; + qre = imaginaryComponentScales.qre; + qim = imaginaryComponentScales.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Complex128( re1[ i ], im1[ i ] ); + z2 = new Complex128( re2[ i ], im2[ i ] ); + q = cdiv( z1, z2 ); + + if ( real( q ) === qre[ i ] ) { + t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); + } else { + delta = abs( real( q ) - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( imag( q ) === qim[ i ] ) { + t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( imag( q ) - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (real imaginary component scales)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = realComponentScales.re1; + im1 = realComponentScales.im1; + re2 = realComponentScales.re2; + im2 = realComponentScales.im2; + qre = realComponentScales.qre; + qim = realComponentScales.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Complex128( re1[ i ], im1[ i ] ); + z2 = new Complex128( re2[ i ], im2[ i ] ); + q = cdiv( z1, z2 ); + + if ( real( q ) === qre[ i ] ) { + t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); + } else { + delta = abs( real( q ) - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( imag( q ) === qim[ i ] ) { + t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( imag( q ) - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (large negative imaginary components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = largeNegativeImaginaryComponents.re1; + im1 = largeNegativeImaginaryComponents.im1; + re2 = largeNegativeImaginaryComponents.re2; + im2 = largeNegativeImaginaryComponents.im2; + qre = largeNegativeImaginaryComponents.qre; + qim = largeNegativeImaginaryComponents.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Complex128( re1[ i ], im1[ i ] ); + z2 = new Complex128( re2[ i ], im2[ i ] ); + q = cdiv( z1, z2 ); + + if ( real( q ) === qre[ i ] ) { + t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); + } else { + delta = abs( real( q ) - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( imag( q ) === qim[ i ] ) { + t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( imag( q ) - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (large negative real components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = largeNegativeRealComponents.re1; + im1 = largeNegativeRealComponents.im1; + re2 = largeNegativeRealComponents.re2; + im2 = largeNegativeRealComponents.im2; + qre = largeNegativeRealComponents.qre; + qim = largeNegativeRealComponents.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Complex128( re1[ i ], im1[ i ] ); + z2 = new Complex128( re2[ i ], im2[ i ] ); + q = cdiv( z1, z2 ); + + if ( real( q ) === qre[ i ] ) { + t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); + } else { + delta = abs( real( q ) - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( imag( q ) === qim[ i ] ) { + t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( imag( q ) - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (large positive imaginary components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = largePositiveImaginaryComponents.re1; + im1 = largePositiveImaginaryComponents.im1; + re2 = largePositiveImaginaryComponents.re2; + im2 = largePositiveImaginaryComponents.im2; + qre = largePositiveImaginaryComponents.qre; + qim = largePositiveImaginaryComponents.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Complex128( re1[ i ], im1[ i ] ); + z2 = new Complex128( re2[ i ], im2[ i ] ); + q = cdiv( z1, z2 ); + + if ( real( q ) === qre[ i ] ) { + t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); + } else { + delta = abs( real( q ) - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( imag( q ) === qim[ i ] ) { + t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( imag( q ) - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (large positive real components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = largePositiveRealComponents.re1; + im1 = largePositiveRealComponents.im1; + re2 = largePositiveRealComponents.re2; + im2 = largePositiveRealComponents.im2; + qre = largePositiveRealComponents.qre; + qim = largePositiveRealComponents.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Complex128( re1[ i ], im1[ i ] ); + z2 = new Complex128( re2[ i ], im2[ i ] ); + q = cdiv( z1, z2 ); + + if ( real( q ) === qre[ i ] ) { + t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); + } else { + delta = abs( real( q ) - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( imag( q ) === qim[ i ] ) { + t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( imag( q ) - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (tiny negative imaginary components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = tinyNegativeImaginaryComponents.re1; + im1 = tinyNegativeImaginaryComponents.im1; + re2 = tinyNegativeImaginaryComponents.re2; + im2 = tinyNegativeImaginaryComponents.im2; + qre = tinyNegativeImaginaryComponents.qre; + qim = tinyNegativeImaginaryComponents.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Complex128( re1[ i ], im1[ i ] ); + z2 = new Complex128( re2[ i ], im2[ i ] ); + q = cdiv( z1, z2 ); + + if ( real( q ) === qre[ i ] ) { + t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); + } else { + delta = abs( real( q ) - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( imag( q ) === qim[ i ] ) { + t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( imag( q ) - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (tiny negative real components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = tinyNegativeRealComponents.re1; + im1 = tinyNegativeRealComponents.im1; + re2 = tinyNegativeRealComponents.re2; + im2 = tinyNegativeRealComponents.im2; + qre = tinyNegativeRealComponents.qre; + qim = tinyNegativeRealComponents.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Complex128( re1[ i ], im1[ i ] ); + z2 = new Complex128( re2[ i ], im2[ i ] ); + q = cdiv( z1, z2 ); + + if ( real( q ) === qre[ i ] ) { + t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); + } else { + delta = abs( real( q ) - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( imag( q ) === qim[ i ] ) { + t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( imag( q ) - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (tiny positive imaginary components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = tinyPositiveImaginaryComponents.re1; + im1 = tinyPositiveImaginaryComponents.im1; + re2 = tinyPositiveImaginaryComponents.re2; + im2 = tinyPositiveImaginaryComponents.im2; + qre = tinyPositiveImaginaryComponents.qre; + qim = tinyPositiveImaginaryComponents.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Complex128( re1[ i ], im1[ i ] ); + z2 = new Complex128( re2[ i ], im2[ i ] ); + q = cdiv( z1, z2 ); + + if ( real( q ) === qre[ i ] ) { + t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); + } else { + delta = abs( real( q ) - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( imag( q ) === qim[ i ] ) { + t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( imag( q ) - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (tiny positive real components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = tinyPositiveRealComponents.re1; + im1 = tinyPositiveRealComponents.im1; + re2 = tinyPositiveRealComponents.re2; + im2 = tinyPositiveRealComponents.im2; + qre = tinyPositiveRealComponents.qre; + qim = tinyPositiveRealComponents.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Complex128( re1[ i ], im1[ i ] ); + z2 = new Complex128( re2[ i ], im2[ i ] ); + q = cdiv( z1, z2 ); + + if ( real( q ) === qre[ i ] ) { + t.strictEqual( real( q ), qre[ i ], 'returns expected real component' ); + } else { + delta = abs( real( q ) - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+real( q )+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( imag( q ) === qim[ i ] ) { + t.strictEqual( imag( q ), qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( imag( q ) - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+imag( q )+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function handles large and small numbers', function test( t ) { + var expected; + var z1; + var z2; + var v; + + z1 = new Complex128( 1.0e308, 5.0e307 ); + z2 = new Complex128( 1.0, 0.5 ); + v = cdiv( z1, z2 ); + expected = [ 1.0e308, 0.0 ]; + + t.strictEqual( real( v ), expected[ 0 ], 'returns expected values' ); + t.strictEqual( imag( v ), expected[ 1 ], 'returns expected values' ); + + z1 = new Complex128( 1.0, 0.5 ); + z2 = new Complex128( 1.0e308, 5.0e307 ); + v = cdiv( z1, z2 ); + expected = [ 1.0e-308, 0.0 ]; + + t.strictEqual( real( v ), expected[ 0 ], 'returns expected values' ); + t.strictEqual( imag( v ), expected[ 1 ], 'returns expected values' ); + + z1 = new Complex128( 1.0e-304, 2.0e-304 ); + z2 = new Complex128( 1.0, 2.0 ); + v = cdiv( z1, z2 ); + expected = [ 1.0e-304, 0.0 ]; + + t.strictEqual( real( v ), expected[ 0 ], 'returns expected values' ); + t.strictEqual( imag( v ), expected[ 1 ], 'returns expected values' ); + + z1 = new Complex128( 1.0, 2.0 ); + z2 = new Complex128( 1.0e-304, 2.0e-304 ); + v = cdiv( z1, z2 ); + expected = [ 1.0e+304, 0.0 ]; + + t.strictEqual( real( v ), expected[ 0 ], 'returns expected values' ); + t.strictEqual( imag( v ), expected[ 1 ], 'returns expected values' ); + + z1 = new Complex128( 2.0, 4.0 ); + z2 = new Complex128( 0.0, 2.0 ); + v = cdiv( z1, z2 ); + expected = [ 2.0, -1.0 ]; + + t.strictEqual( real( v ), expected[ 0 ], 'returns expected values' ); + t.strictEqual( imag( v ), expected[ 1 ], 'returns expected values' ); + + z1 = new Complex128( 1.0e-180, 1.0e-180 ); + z2 = new Complex128( 1.0, 1.0e-180 ); + v = cdiv( z1, z2 ); + expected = [ 1.0e-180, 1.0e-180 ]; + + t.strictEqual( real( v ), expected[ 0 ], 'returns expected values' ); + t.strictEqual( imag( v ), expected[ 1 ], 'returns expected values' ); + + t.end(); +}); + +tape( 'the function may overflow during complex division', function test( t ) { + var z1; + var z2; + var v; + + z1 = new Complex128( 1.0e308, 1.0e308 ); + z2 = new Complex128( 5.0e-324, 5.0e-324 ); + v = cdiv( z1, z2 ); + t.strictEqual( real( v ), PINF, 'real component is +infinity' ); + t.strictEqual( imag( v ), 0.0, 'imaginary component is 0' ); + + z1 = new Complex128( 1.0e308, 1.0e308 ); + z2 = new Complex128( -5.0e-324, 5.0e-324 ); + v = cdiv( z1, z2 ); + t.strictEqual( real( v ), 0.0, 'real component is 0' ); + t.strictEqual( imag( v ), NINF, 'imaginary component is -infinity' ); + + z1 = new Complex128( 1.0e308, -1.0e308 ); + z2 = new Complex128( 5.0e-324, 5.0e-324 ); + v = cdiv( z1, z2 ); + t.strictEqual( real( v ), 0.0, 'real component is 0' ); + t.strictEqual( imag( v ), NINF, 'imaginary component is -infinity' ); + + z1 = new Complex128( -1.0e308, 1.0e308 ); + z2 = new Complex128( 5.0e-324, 5.0e-324 ); + v = cdiv( z1, z2 ); + t.strictEqual( real( v ), 0.0, 'real component is 0' ); + t.strictEqual( imag( v ), PINF, 'imaginary component is +infinity' ); + + z1 = new Complex128( 1.0e308, 1.0e308 ); + z2 = new Complex128( 5.0e-324, -5.0e-324 ); + v = cdiv( z1, z2 ); + t.strictEqual( real( v ), 0.0, 'real component is 0' ); + t.strictEqual( imag( v ), PINF, 'imaginary component is +infinity' ); + + z1 = new Complex128( -1.0e308, 1.0e308 ); + z2 = new Complex128( -5.0e-324, 5.0e-324 ); + v = cdiv( z1, z2 ); + t.strictEqual( real( v ), PINF, 'real component is +infinity' ); + t.strictEqual( imag( v ), 0.0, 'imaginary component is 0' ); + + z1 = new Complex128( 1.0e308, -1.0e308 ); + z2 = new Complex128( 5.0e-324, -5.0e-324 ); + v = cdiv( z1, z2 ); + t.strictEqual( real( v ), PINF, 'real component is +infinity' ); + t.strictEqual( imag( v ), 0.0, 'imaginary component is 0' ); + + z1 = new Complex128( 1.0e308, -1.0e308 ); + z2 = new Complex128( -5.0e-324, 5.0e-324 ); + v = cdiv( z1, z2 ); + t.strictEqual( real( v ), NINF, 'real component is -infinity' ); + t.strictEqual( imag( v ), 0.0, 'imaginary component is 0' ); + + z1 = new Complex128( -1.0e308, 1.0e308 ); + z2 = new Complex128( 5.0e-324, -5.0e-324 ); + v = cdiv( z1, z2 ); + t.strictEqual( real( v ), NINF, 'real component is -infinity' ); + t.strictEqual( imag( v ), 0.0, 'imaginary component is 0' ); + + z1 = new Complex128( -1.0e308, -1.0e308 ); + z2 = new Complex128( -5.0e-324, 5.0e-324 ); + v = cdiv( z1, z2 ); + t.strictEqual( real( v ), 0.0, 'real component is 0' ); + t.strictEqual( imag( v ), PINF, 'imaginary component is +infinity' ); + + z1 = new Complex128( 1.0e308, -1.0e308 ); + z2 = new Complex128( -5.0e-324, -5.0e-324 ); + v = cdiv( z1, z2 ); + t.strictEqual( real( v ), 0.0, 'real component is 0' ); + t.strictEqual( imag( v ), PINF, 'imaginary component is +infinity' ); + + z1 = new Complex128( -1.0e308, 1.0e308 ); + z2 = new Complex128( -5.0e-324, -5.0e-324 ); + v = cdiv( z1, z2 ); + t.strictEqual( real( v ), 0.0, 'real component is 0' ); + t.strictEqual( imag( v ), NINF, 'imaginary component is -infinity' ); + + z1 = new Complex128( -1.0e308, -1.0e308 ); + z2 = new Complex128( 5.0e-324, -5.0e-324 ); + v = cdiv( z1, z2 ); + t.strictEqual( real( v ), 0.0, 'real component is 0' ); + t.strictEqual( imag( v ), NINF, 'imaginary component is -infinity' ); + + t.end(); +}); + +tape( 'if a real or imaginary component is `NaN`, all components are `NaN`', function test( t ) { + var z1; + var z2; + var v; + + z1 = new Complex128( NaN, 3.0 ); + z2 = new Complex128( -2.0, 1.0 ); + v = cdiv( z1, z2 ); + t.strictEqual( isnan( real( v ) ), true, 'returns NaN' ); + t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' ); + + z1 = new Complex128( 5.0, NaN ); + z2 = new Complex128( -2.0, 1.0 ); + v = cdiv( z1, z2 ); + t.strictEqual( isnan( real( v ) ), true, 'returns NaN' ); + t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' ); + + z1 = new Complex128( 5.0, 3.0 ); + z2 = new Complex128( NaN, 1.0 ); + v = cdiv( z1, z2 ); + t.strictEqual( isnan( real( v ) ), true, 'returns NaN' ); + t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' ); + + z1 = new Complex128( 5.0, 3.0 ); + z2 = new Complex128( -2.0, NaN ); + v = cdiv( z1, z2 ); + t.strictEqual( isnan( real( v ) ), true, 'returns NaN' ); + t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' ); + + z1 = new Complex128( 5.0, 3.0 ); + z2 = new Complex128( NaN, NaN ); + v = cdiv( z1, z2 ); + t.strictEqual( isnan( real( v ) ), true, 'returns NaN' ); + t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' ); + + z1 = new Complex128( NaN, NaN ); + z2 = new Complex128( -2.0, 1.0 ); + v = cdiv( z1, z2 ); + t.strictEqual( isnan( real( v ) ), true, 'returns NaN' ); + t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' ); + + z1 = new Complex128( NaN, NaN ); + z2 = new Complex128( NaN, NaN ); + v = cdiv( z1, z2 ); + t.strictEqual( isnan( real( v ) ), true, 'returns NaN' ); + t.strictEqual( isnan( imag( v ) ), true, 'returns NaN' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/complex/float64/base/div/test/test.native.js b/lib/node_modules/@stdlib/complex/float64/base/div/test/test.native.js index 54c15706f665..74f1a15a7d84 100644 --- a/lib/node_modules/@stdlib/complex/float64/base/div/test/test.native.js +++ b/lib/node_modules/@stdlib/complex/float64/base/div/test/test.native.js @@ -16,7 +16,7 @@ * limitations under the License. */ -/* eslint-disable id-length */ +/* eslint-disable id-length, max-statements */ 'use strict'; diff --git a/lib/node_modules/@stdlib/complex/float64/base/div/test/test.strided.js b/lib/node_modules/@stdlib/complex/float64/base/div/test/test.strided.js new file mode 100644 index 000000000000..36d75f665166 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float64/base/div/test/test.strided.js @@ -0,0 +1,1054 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable id-length, max-statements */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var isAlmostEqualFloat64Array = require( '@stdlib/assert/is-almost-equal-float64array' ); +var toBinaryString = require( '@stdlib/number/float64/base/to-binary-string' ); +var Float64Array = require( '@stdlib/array/float64' ); +var cdiv = require( './../lib/strided.js' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); +var componentScales1 = require( './fixtures/julia/component_scales1.json' ); +var componentScales2 = require( './fixtures/julia/component_scales2.json' ); +var imaginaryComponentScales = require( './fixtures/julia/imaginary_component_scales.json' ); +var realComponentScales = require( './fixtures/julia/real_component_scales.json' ); +var largeNegativeImaginaryComponents = require( './fixtures/julia/large_negative_imaginary_components.json' ); +var largeNegativeRealComponents = require( './fixtures/julia/large_negative_real_components.json' ); +var largePositiveImaginaryComponents = require( './fixtures/julia/large_positive_imaginary_components.json' ); +var largePositiveRealComponents = require( './fixtures/julia/large_positive_real_components.json' ); +var tinyNegativeImaginaryComponents = require( './fixtures/julia/tiny_negative_imaginary_components.json' ); +var tinyNegativeRealComponents = require( './fixtures/julia/tiny_negative_real_components.json' ); +var tinyPositiveImaginaryComponents = require( './fixtures/julia/tiny_positive_imaginary_components.json' ); +var tinyPositiveRealComponents = require( './fixtures/julia/tiny_positive_real_components.json' ); + + +// FUNCTIONS // + +/** +* Compares the binary representations of two double-precision floating-point numbers and returns the first index of a differing bit. If all bits match, the function returns `-1`. +* +* TODO: revisit once ULP distance fcn is written +* +* @private +* @param {number} a - first number +* @param {number} b - second number +* @returns {integer} index +*/ +function bitdiff( a, b ) { + var astr; + var bstr; + var i; + + astr = toBinaryString( a ); + bstr = toBinaryString( b ); + for ( i = 0; i < 64; i++ ) { + if ( astr[ i ] !== bstr[ i ] ) { + return i; + } + } + return -1; +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cdiv, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function computes a complex quotient (base behavior)', function test( t ) { + var expected; + var out; + var z1; + var z2; + var v; + + out = new Float64Array( 2 ); + z1 = new Float64Array( [ 2.0, 4.0 ] ); + z2 = new Float64Array( [ 1.0, 2.0 ] ); + expected = new Float64Array( [ 2.0, 0.0 ] ); + + v = cdiv( z1, 1, 0, z2, 1, 0, out, 1, 0 ); + + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + t.end(); +}); + +tape( 'the function computes a complex quotient (difficult cases)', function test( t ) { + var idx; + var re1; + var im1; + var re2; + var im2; + var z1; + var z2; + var q; + + // Note: test cases extracted from Figure 6 of https://arxiv.org/pdf/1210.4539.pdf. + + // Test case #1: + z1 = new Float64Array( [ 1.0, 1.0 ] ); + z2 = new Float64Array( [ 1.0, pow( 2.0, 1023.0 ) ] ); + + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + idx = bitdiff( q[ 0 ], pow( 2.0, -1023.0 ) ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( q[ 1 ], -pow( 2.0, -1023.0 ) ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #2: + z1 = new Float64Array( [ 1.0, 1.0 ] ); + z2 = new Float64Array( [ pow( 2.0, -1023.0 ), pow( 2.0, -1023.0 ) ] ); + + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + idx = bitdiff( q[ 0 ], pow( 2.0, 1023.0 ) ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( q[ 1 ], 0.0 ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #3: + re1 = pow( 2.0, 1023.0 ); + im1 = pow( 2.0, -1023.0 ); + re2 = pow( 2.0, 677.0 ); + im2 = pow( 2.0, -677.0 ); + + z1 = new Float64Array( [ re1, im1 ] ); + z2 = new Float64Array( [ re2, im2 ] ); + + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + idx = bitdiff( q[ 0 ], pow( 2.0, 346.0 ) ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( q[ 1 ], -pow( 2.0, -1008.0 ) ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #4: + z1 = new Float64Array( [ pow( 2.0, 1023.0 ), pow( 2.0, 1023.0 ) ] ); + z2 = new Float64Array( [ 1.0, 1.0 ] ); + + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + idx = bitdiff( q[ 0 ], pow( 2.0, 1023.0 ) ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( q[ 1 ], 0.0 ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #5: + re1 = pow( 2.0, 1020.0 ); + im1 = pow( 2.0, -844.0 ); + re2 = pow( 2.0, 656.0 ); + im2 = pow( 2.0, -780.0 ); + + z1 = new Float64Array( [ re1, im1 ] ); + z2 = new Float64Array( [ re2, im2 ] ); + + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + idx = bitdiff( q[ 0 ], pow( 2.0, 364.0 ) ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( q[ 1 ], -pow( 2.0, -1072.0 ) ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #6: + re1 = pow( 2.0, -71.0 ); + im1 = pow( 2.0, 1021.0 ); + re2 = pow( 2.0, 1001.0 ); + im2 = pow( 2.0, -323.0 ); + + z1 = new Float64Array( [ re1, im1 ] ); + z2 = new Float64Array( [ re2, im2 ] ); + + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + idx = bitdiff( q[ 0 ], pow( 2.0, -1072.0 ) ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( q[ 1 ], pow( 2.0, 20.0 ) ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #7: + re1 = pow( 2.0, -347.0 ); + im1 = pow( 2.0, -54.0 ); + re2 = pow( 2.0, -1037.0 ); + im2 = pow( 2.0, -1058.0 ); + + z1 = new Float64Array( [ re1, im1 ] ); + z2 = new Float64Array( [ re2, im2 ] ); + + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + idx = bitdiff( q[ 0 ], 3.898125604559113300e289 ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( q[ 1 ], 8.174961907852353577e295 ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #8: + re1 = pow( 2.0, -1074.0 ); + im1 = pow( 2.0, -1074.0 ); + re2 = pow( 2.0, -1073.0 ); + im2 = pow( 2.0, -1074.0 ); + + z1 = new Float64Array( [ re1, im1 ] ); + z2 = new Float64Array( [ re2, im2 ] ); + + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + /* + * See section 3.6 in https://arxiv.org/pdf/1210.4539.pdf. + * + * ```text + * real(q): 0011111111100011001100110011001100110011001100110011001100110100 + * 0.6: 0011111111100011001100110011001100110011001100110011001100110011 + * ``` + * + * If we add + * + * ```text + * 0000000000000000000000000000000000000000000000000000000000000001 + * ``` + * + * to `0.6`, we get `real( q )`; thus, the result is 1 bit off. + */ + idx = bitdiff( q[ 0 ], 0.6 ); + t.strictEqual( idx, 61, 'real component has expected binary representation' ); + + idx = bitdiff( q[ 1 ], 0.2 ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #9: + re1 = pow( 2.0, 1015.0 ); + im1 = pow( 2.0, -989.0 ); + re2 = pow( 2.0, 1023.0 ); + im2 = pow( 2.0, 1023.0 ); + + z1 = new Float64Array( [ re1, im1 ] ); + z2 = new Float64Array( [ re2, im2 ] ); + + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + idx = bitdiff( q[ 0 ], 0.001953125 ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( q[ 1 ], -0.001953125 ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + // Test case #10: + re1 = pow( 2.0, -622.0 ); + im1 = pow( 2.0, -1071.0 ); + re2 = pow( 2.0, -343.0 ); + im2 = pow( 2.0, -798.0 ); + + z1 = new Float64Array( [ re1, im1 ] ); + z2 = new Float64Array( [ re2, im2 ] ); + + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + idx = bitdiff( q[ 0 ], 1.02951151789360578e-84 ); + t.strictEqual( idx, -1, 'real component has expected binary representation' ); + + idx = bitdiff( q[ 1 ], 6.97145987515076231e-220 ); + t.strictEqual( idx, -1, 'imaginary component has expected binary representation' ); + + t.end(); +}); + +tape( 'the function computes a complex quotient (tested against fixtures)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = data.re1; + im1 = data.im1; + re2 = data.re2; + im2 = data.im2; + qre = data.qre; + qim = data.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Float64Array( [ re1[ i ], im1[ i ] ] ); + z2 = new Float64Array( [ re2[ i ], im2[ i ] ] ); + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (different component scales)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = componentScales1.re1; + im1 = componentScales1.im1; + re2 = componentScales1.re2; + im2 = componentScales1.im2; + qre = componentScales1.qre; + qim = componentScales1.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Float64Array( [ re1[ i ], im1[ i ] ] ); + z2 = new Float64Array( [ re2[ i ], im2[ i ] ] ); + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (different component scales)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = componentScales2.re1; + im1 = componentScales2.im1; + re2 = componentScales2.re2; + im2 = componentScales2.im2; + qre = componentScales2.qre; + qim = componentScales2.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Float64Array( [ re1[ i ], im1[ i ] ] ); + z2 = new Float64Array( [ re2[ i ], im2[ i ] ] ); + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (different imaginary component scales)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = imaginaryComponentScales.re1; + im1 = imaginaryComponentScales.im1; + re2 = imaginaryComponentScales.re2; + im2 = imaginaryComponentScales.im2; + qre = imaginaryComponentScales.qre; + qim = imaginaryComponentScales.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Float64Array( [ re1[ i ], im1[ i ] ] ); + z2 = new Float64Array( [ re2[ i ], im2[ i ] ] ); + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (real imaginary component scales)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = realComponentScales.re1; + im1 = realComponentScales.im1; + re2 = realComponentScales.re2; + im2 = realComponentScales.im2; + qre = realComponentScales.qre; + qim = realComponentScales.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Float64Array( [ re1[ i ], im1[ i ] ] ); + z2 = new Float64Array( [ re2[ i ], im2[ i ] ] ); + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (large negative imaginary components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = largeNegativeImaginaryComponents.re1; + im1 = largeNegativeImaginaryComponents.im1; + re2 = largeNegativeImaginaryComponents.re2; + im2 = largeNegativeImaginaryComponents.im2; + qre = largeNegativeImaginaryComponents.qre; + qim = largeNegativeImaginaryComponents.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Float64Array( [ re1[ i ], im1[ i ] ] ); + z2 = new Float64Array( [ re2[ i ], im2[ i ] ] ); + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (large negative real components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = largeNegativeRealComponents.re1; + im1 = largeNegativeRealComponents.im1; + re2 = largeNegativeRealComponents.re2; + im2 = largeNegativeRealComponents.im2; + qre = largeNegativeRealComponents.qre; + qim = largeNegativeRealComponents.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Float64Array( [ re1[ i ], im1[ i ] ] ); + z2 = new Float64Array( [ re2[ i ], im2[ i ] ] ); + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (large positive imaginary components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = largePositiveImaginaryComponents.re1; + im1 = largePositiveImaginaryComponents.im1; + re2 = largePositiveImaginaryComponents.re2; + im2 = largePositiveImaginaryComponents.im2; + qre = largePositiveImaginaryComponents.qre; + qim = largePositiveImaginaryComponents.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Float64Array( [ re1[ i ], im1[ i ] ] ); + z2 = new Float64Array( [ re2[ i ], im2[ i ] ] ); + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (large positive real components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = largePositiveRealComponents.re1; + im1 = largePositiveRealComponents.im1; + re2 = largePositiveRealComponents.re2; + im2 = largePositiveRealComponents.im2; + qre = largePositiveRealComponents.qre; + qim = largePositiveRealComponents.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Float64Array( [ re1[ i ], im1[ i ] ] ); + z2 = new Float64Array( [ re2[ i ], im2[ i ] ] ); + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (tiny negative imaginary components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = tinyNegativeImaginaryComponents.re1; + im1 = tinyNegativeImaginaryComponents.im1; + re2 = tinyNegativeImaginaryComponents.re2; + im2 = tinyNegativeImaginaryComponents.im2; + qre = tinyNegativeImaginaryComponents.qre; + qim = tinyNegativeImaginaryComponents.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Float64Array( [ re1[ i ], im1[ i ] ] ); + z2 = new Float64Array( [ re2[ i ], im2[ i ] ] ); + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (tiny negative real components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = tinyNegativeRealComponents.re1; + im1 = tinyNegativeRealComponents.im1; + re2 = tinyNegativeRealComponents.re2; + im2 = tinyNegativeRealComponents.im2; + qre = tinyNegativeRealComponents.qre; + qim = tinyNegativeRealComponents.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Float64Array( [ re1[ i ], im1[ i ] ] ); + z2 = new Float64Array( [ re2[ i ], im2[ i ] ] ); + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (tiny positive imaginary components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = tinyPositiveImaginaryComponents.re1; + im1 = tinyPositiveImaginaryComponents.im1; + re2 = tinyPositiveImaginaryComponents.re2; + im2 = tinyPositiveImaginaryComponents.im2; + qre = tinyPositiveImaginaryComponents.qre; + qim = tinyPositiveImaginaryComponents.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Float64Array( [ re1[ i ], im1[ i ] ] ); + z2 = new Float64Array( [ re2[ i ], im2[ i ] ] ); + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function computes a complex quotient (tiny positive real components)', function test( t ) { + var delta; + var tol; + var re1; + var im1; + var re2; + var im2; + var qre; + var qim; + var z1; + var z2; + var i; + var q; + + re1 = tinyPositiveRealComponents.re1; + im1 = tinyPositiveRealComponents.im1; + re2 = tinyPositiveRealComponents.re2; + im2 = tinyPositiveRealComponents.im2; + qre = tinyPositiveRealComponents.qre; + qim = tinyPositiveRealComponents.qim; + + for ( i = 0; i < re1.length; i++ ) { + z1 = new Float64Array( [ re1[ i ], im1[ i ] ] ); + z2 = new Float64Array( [ re2[ i ], im2[ i ] ] ); + q = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + + if ( q[ 0 ] === qre[ i ] ) { + t.strictEqual( q[ 0 ], qre[ i ], 'returns expected real component' ); + } else { + delta = abs( q[ 0 ] - qre[ i ] ); + tol = EPS * abs( qre[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. real: '+q[0]+'. expected: '+qre[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + if ( q[ 1 ] === qim[ i ] ) { + t.strictEqual( q[ 1 ], qim[ i ], 'returns expected imaginary component' ); + } else { + delta = abs( q[ 1 ] - qim[ i ] ); + tol = EPS * abs( qim[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+re1[i]+' + '+im1[i]+'i. y: '+re2[i]+' + '+im2[i]+'i. imag: '+q[1]+'. expected: '+qim[i]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); + +tape( 'the function handles large and small numbers', function test( t ) { + var expected; + var z1; + var z2; + var v; + + z1 = new Float64Array( [ 1.0e308, 5.0e307 ] ); + z2 = new Float64Array( [ 1.0, 0.5 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ 1.0e308, 0.0 ] ); + + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + z1 = new Float64Array( [ 1.0, 0.5 ] ); + z2 = new Float64Array( [ 1.0e308, 5.0e307 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ 1.0e-308, 0.0 ] ); + + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + z1 = new Float64Array( [ 1.0e-304, 2.0e-304 ] ); + z2 = new Float64Array( [ 1.0, 2.0 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ 1.0e-304, 0.0 ] ); + + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + z1 = new Float64Array( [ 1.0, 2.0 ] ); + z2 = new Float64Array( [ 1.0e-304, 2.0e-304 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ 1.0e+304, 0.0 ] ); + + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + z1 = new Float64Array( [ 2.0, 4.0 ] ); + z2 = new Float64Array( [ 0.0, 2.0 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ 2.0, -1.0 ] ); + + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + z1 = new Float64Array( [ 1.0e-180, 1.0e-180 ] ); + z2 = new Float64Array( [ 1.0, 1.0e-180 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ 1.0e-180, 1.0e-180 ] ); + + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + t.end(); +}); + +tape( 'the function may overflow during complex division', function test( t ) { + var expected; + var z1; + var z2; + var v; + + z1 = new Float64Array( [ 1.0e308, 1.0e308 ] ); + z2 = new Float64Array( [ 5.0e-324, 5.0e-324 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ PINF, 0.0 ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + z1 = new Float64Array( [ 1.0e308, 1.0e308 ] ); + z2 = new Float64Array( [ -5.0e-324, 5.0e-324 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ 0.0, NINF ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + z1 = new Float64Array( [ 1.0e308, -1.0e308 ] ); + z2 = new Float64Array( [ 5.0e-324, 5.0e-324 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ 0.0, NINF ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + z1 = new Float64Array( [ -1.0e308, 1.0e308 ] ); + z2 = new Float64Array( [ 5.0e-324, 5.0e-324 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ 0.0, PINF ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + z1 = new Float64Array( [ 1.0e308, 1.0e308 ] ); + z2 = new Float64Array( [ 5.0e-324, -5.0e-324 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ 0.0, PINF ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + z1 = new Float64Array( [ -1.0e308, 1.0e308 ] ); + z2 = new Float64Array( [ -5.0e-324, 5.0e-324 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ PINF, 0.0 ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + z1 = new Float64Array( [ 1.0e308, -1.0e308 ] ); + z2 = new Float64Array( [ 5.0e-324, -5.0e-324 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ PINF, 0.0 ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + z1 = new Float64Array( [ 1.0e308, -1.0e308 ] ); + z2 = new Float64Array( [ -5.0e-324, 5.0e-324 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ NINF, 0.0 ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + z1 = new Float64Array( [ -1.0e308, 1.0e308 ] ); + z2 = new Float64Array( [ 5.0e-324, -5.0e-324 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ NINF, 0.0 ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + z1 = new Float64Array( [ -1.0e308, -1.0e308 ] ); + z2 = new Float64Array( [ -5.0e-324, 5.0e-324 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ 0.0, PINF ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + z1 = new Float64Array( [ 1.0e308, -1.0e308 ] ); + z2 = new Float64Array( [ -5.0e-324, -5.0e-324 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ 0.0, PINF ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + z1 = new Float64Array( [ -1.0e308, 1.0e308 ] ); + z2 = new Float64Array( [ -5.0e-324, -5.0e-324 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ 0.0, NINF ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + z1 = new Float64Array( [ -1.0e308, -1.0e308 ] ); + z2 = new Float64Array( [ 5.0e-324, -5.0e-324 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + expected = new Float64Array( [ 0.0, NINF ] ); + t.strictEqual( isAlmostEqualFloat64Array( v, expected, EPS ), true, 'returns expected values' ); + + t.end(); +}); + +tape( 'if a real or imaginary component is `NaN`, all components are `NaN`', function test( t ) { + var z1; + var z2; + var v; + + z1 = new Float64Array( [ NaN, 3.0 ] ); + z2 = new Float64Array( [ -2.0, 1.0 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + z1 = new Float64Array( [ 5.0, NaN ] ); + z2 = new Float64Array( [ -2.0, 1.0 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + z1 = new Float64Array( [ 5.0, 3.0 ] ); + z2 = new Float64Array( [ NaN, 1.0 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + z1 = new Float64Array( [ 5.0, 3.0 ] ); + z2 = new Float64Array( [ -2.0, NaN ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + z1 = new Float64Array( [ 5.0, 3.0 ] ); + z2 = new Float64Array( [ NaN, NaN ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + z1 = new Float64Array( [ NaN, NaN ] ); + z2 = new Float64Array( [ -2.0, 1.0 ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + z1 = new Float64Array( [ NaN, NaN ] ); + z2 = new Float64Array( [ NaN, NaN ] ); + v = cdiv( z1, 1, 0, z2, 1, 0, new Float64Array( 2 ), 1, 0 ); + t.strictEqual( isnan( v[ 0 ] ), true, 'returns NaN' ); + t.strictEqual( isnan( v[ 1 ] ), true, 'returns NaN' ); + + t.end(); +});