diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/README.md b/lib/node_modules/@stdlib/complex/float32/ctor/README.md new file mode 100644 index 00000000000..f23fd8ccd76 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/README.md @@ -0,0 +1,538 @@ + + +# Complex64 + +> 64-bit complex number. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var Complex64 = require( '@stdlib/complex/float32/ctor' ); +``` + +#### Complex64( real, imag ) + +64-bit complex number constructor, where `real` and `imag` are the **real** and **imaginary** components, respectively. + +```javascript +var z = new Complex64( 5.0, 3.0 ); +// returns +``` + +* * * + +## Properties + +#### Complex64.BYTES_PER_ELEMENT + +Size (in bytes) of each component. + +```javascript +var nbytes = Complex64.BYTES_PER_ELEMENT; +// returns 4 +``` + +#### Complex64.prototype.BYTES_PER_ELEMENT + +Size (in bytes) of each component. + +```javascript +var z = new Complex64( 5.0, 3.0 ); + +var nbytes = z.BYTES_PER_ELEMENT; +// returns 4 +``` + +#### Complex64.prototype.byteLength + +Length (in bytes) of a complex number. + +```javascript +var z = new Complex64( 5.0, 3.0 ); + +var nbytes = z.byteLength; +// returns 8 +``` + +### Instance + +A `Complex64` instance has the following properties... + +#### re + +A **read-only** property returning the **real** component. + +```javascript +var z = new Complex64( 5.0, 3.0 ); + +var re = z.re; +// returns 5.0 +``` + +#### im + +A **read-only** property returning the **imaginary** component. + +```javascript +var z = new Complex64( 5.0, -3.0 ); + +var im = z.im; +// returns -3.0 +``` + +* * * + +## Methods + +### Accessor Methods + +These methods do **not** mutate a `Complex64` instance and, instead, return a complex number representation. + +#### Complex64.prototype.toString() + +Returns a `string` representation of a `Complex64` instance. + +```javascript +var z = new Complex64( 5.0, 3.0 ); +var str = z.toString(); +// returns '5 + 3i' + +z = new Complex64( -5.0, -3.0 ); +str = z.toString(); +// returns '-5 - 3i' +``` + +#### Complex64.prototype.toJSON() + +Returns a [JSON][json] representation of a `Complex64` instance. [`JSON.stringify()`][mdn-json-stringify] implicitly calls this method when stringifying a `Complex64` instance. + +```javascript +var z = new Complex64( 5.0, -3.0 ); + +var o = z.toJSON(); +/* + { + "type": "Complex64", + "re": 5.0, + "im": -3.0 + } +*/ +``` + +To [revive][mdn-json-parse] a `Complex64` number from a [JSON][json] `string`, see [@stdlib/complex/reviver-float32][@stdlib/complex/reviver-float32]. + +
+ + + +* * * + + + +
+ +## Notes + +- Both the **real** and **imaginary** components are stored as single-precision floating-point numbers. + +
+ + + +* * * + + + +
+ +## Examples + + + +```javascript +var Complex64 = require( '@stdlib/complex/float32/ctor' ); + +var z = new Complex64( 3.0, -2.0 ); + +console.log( 'type: %s', typeof z ); +// => 'type: object' + +console.log( 'str: %s', z ); +// => 'str: 3 - 2i' + +console.log( 'real: %d', z.re ); +// => 'real: 3' + +console.log( 'imaginary: %d', z.im ); +// => 'imaginary: -2' + +console.log( 'JSON: %s', JSON.stringify( z ) ); +// => 'JSON: {"type":"Complex64","re":3,"im":-2}' +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/complex/float32/ctor.h" +``` + +#### stdlib_complex64_t + +An opaque type definition for a single-precision complex floating-point number. + +```c +stdlib_complex64_t z = stdlib_complex64( 5.0f, 2.0f ); +``` + +#### stdlib_complex64_parts_t + +An opaque type definition for a union for accessing the real and imaginary parts of a single-precision complex floating-point number. + +```c +float realf( const stdlib_complex64_t z ) { + stdlib_complex64_parts_t v; + + // Assign a single-precision complex floating-point number: + v.value = z; + + // Extract the real component: + float re = v.parts[ 0 ]; + + return re; +} + +// ... + +// Create a complex number: +stdlib_complex64_t z = stdlib_complex64( 5.0f, 2.0f ); + +// ... + +// Access the real component: +float re = realf( z ); +// returns 5.0f +``` + +The union has the following members: + +- **value**: `stdlib_complex64_t` single-precision complex floating-point number. + +- **parts**: `float[]` array having the following elements: + + - **0**: `float` real component. + - **1**: `float` imaginary component. + +#### stdlib_complex64( real, imag ) + +Returns a single-precision complex floating-point number. + +```c +stdlib_complex64_t z = stdlib_complex64( 5.0f, 2.0f ); +``` + +The function accepts the following arguments: + +- **real**: `[in] float` real component. +- **imag**: `[in] float` imaginary component. + +```c +stdlib_complex64_t stdlib_complex64( const float real, const float imag ); +``` + +#### stdlib_complex64_from_float32( real ) + +Converts a single-precision floating-point number to a single-precision complex floating-point number. + +```c +stdlib_complex64_t z = stdlib_complex64_from_float32( 5.0f ); +``` + +The function accepts the following arguments: + +- **real**: `[in] float` real component. + +```c +stdlib_complex64_t stdlib_complex64_from_float32( const float real ); +``` + +#### stdlib_complex64_from_float64( real ) + +Converts a double-precision floating-point number to a single-precision complex floating-point number. + +```c +stdlib_complex64_t z = stdlib_complex64_from_float64( 5.0 ); +``` + +The function accepts the following arguments: + +- **real**: `[in] double` real component. + +```c +stdlib_complex64_t stdlib_complex64_from_float64( const double real ); +``` + +#### stdlib_complex64_from_complex64( z ) + +Converts (copies) a single-precision complex floating-point number to a single-precision complex floating-point number. + +```c +stdlib_complex64_t z1 = stdlib_complex64( 5.0f, 3.0f ); +stdlib_complex64_t z2 = stdlib_complex64_from_complex64( z1 ); +``` + +The function accepts the following arguments: + +- **z**: `[in] stdlib_complex64_t` single-precision complex floating-point number. + +```c +stdlib_complex64_t stdlib_complex64_from_complex64( const stdlib_complex64_t z ); +``` + +#### stdlib_complex64_from_int8( real ) + +Converts a signed 8-bit integer to a single-precision complex floating-point number. + +```c +stdlib_complex64_t z = stdlib_complex64_from_int8( 5 ); +``` + +The function accepts the following arguments: + +- **real**: `[in] int8_t` real component. + +```c +stdlib_complex64_t stdlib_complex64_from_int8( const int8_t real ); +``` + +#### stdlib_complex64_from_uint8( real ) + +Converts an unsigned 8-bit integer to a single-precision complex floating-point number. + +```c +stdlib_complex64_t z = stdlib_complex64_from_uint8( 5 ); +``` + +The function accepts the following arguments: + +- **real**: `[in] uint8_t` real component. + +```c +stdlib_complex64_t stdlib_complex64_from_uint8( const uint8_t real ); +``` + +#### stdlib_complex64_from_int16( real ) + +Converts a signed 16-bit integer to a single-precision complex floating-point number. + +```c +stdlib_complex64_t z = stdlib_complex64_from_int16( 5 ); +``` + +The function accepts the following arguments: + +- **real**: `[in] int16_t` real component. + +```c +stdlib_complex64_t stdlib_complex64_from_int16( const int16_t real ); +``` + +#### stdlib_complex64_from_uint16( real ) + +Converts an unsigned 16-bit integer to a single-precision complex floating-point number. + +```c +stdlib_complex64_t z = stdlib_complex64_from_uint16( 5 ); +``` + +The function accepts the following arguments: + +- **real**: `[in] uint16_t` real component. + +```c +stdlib_complex64_t stdlib_complex64_from_uint16( const uint16_t real ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/complex/float32/ctor.h" +#include +#include + +/** +* Return the real component of a single-precision complex floating-point number. +* +* @param z complex number +* @return real component +*/ +static float real( const stdlib_complex64_t z ) { + stdlib_complex64_parts_t v; + + // Assign a single-precision complex floating-point number: + v.value = z; + + // Extract the real component: + float re = v.parts[ 0 ]; + + return re; +} + +/** +* Return the imaginary component of a single-precision complex floating-point number. +* +* @param z complex number +* @return imaginary component +*/ +static float imag( const stdlib_complex64_t z ) { + stdlib_complex64_parts_t v; + + // Assign a single-precision complex floating-point number: + v.value = z; + + // Extract the imaginary component: + float im = v.parts[ 1 ]; + + return im; +} + +int main( void ) { + const stdlib_complex64_t x[] = { + stdlib_complex64( 5.0f, 2.0f ), + stdlib_complex64( -2.0f, 1.0f ), + stdlib_complex64( 0.0f, -0.0f ), + stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f ) + }; + + stdlib_complex64_t v; + int i; + for ( i = 0; i < 4; i++ ) { + v = x[ i ]; + printf( "%f + %fi\n", real( v ), imag( v ) ); + } +} +``` + +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/benchmark/benchmark.js b/lib/node_modules/@stdlib/complex/float32/ctor/benchmark/benchmark.js new file mode 100644 index 00000000000..4b894a235c1 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/benchmark/benchmark.js @@ -0,0 +1,136 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 randu = require( '@stdlib/random/base/randu' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pkg = require( './../package.json' ).name; +var Complex64 = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var z; + var i; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = new Complex64( i, i ); + if ( isnan( z ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !( z instanceof Complex64 ) ) { + b.fail( 'should return a complex number' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:real', function benchmark( b ) { + var re; + var z; + var i; + + z = new Complex64( randu(), randu() ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + re = z.re; + if ( isnan( re ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( re ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::get:imag', function benchmark( b ) { + var im; + var z; + var i; + + z = new Complex64( randu(), randu() ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + im = z.im; + if ( isnan( im ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( im ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':toString', function benchmark( b ) { + var o; + var z; + var i; + + z = new Complex64( randu(), randu() ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = z.toString(); + if ( typeof o !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( typeof o !== 'string' ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':toJSON', function benchmark( b ) { + var o; + var z; + var i; + + z = new Complex64( randu(), randu() ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + o = z.toJSON(); + if ( typeof o !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( typeof o !== 'object' ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/benchmark/julia/REQUIRE b/lib/node_modules/@stdlib/complex/float32/ctor/benchmark/julia/REQUIRE new file mode 100644 index 00000000000..98645e192e4 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/benchmark/julia/REQUIRE @@ -0,0 +1,2 @@ +julia 1.5 +BenchmarkTools 0.5.0 diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/benchmark/julia/benchmark.jl b/lib/node_modules/@stdlib/complex/float32/ctor/benchmark/julia/benchmark.jl new file mode 100755 index 00000000000..7fae6c3b91c --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/benchmark/julia/benchmark.jl @@ -0,0 +1,144 @@ +#!/usr/bin/env julia +# +# @license Apache-2.0 +# +# Copyright (c) 2018 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. + +import BenchmarkTools +using Printf + +# Benchmark variables: +name = "complex64"; +repeats = 3; + +""" + print_version() + +Prints the TAP version. + +# Examples + +``` julia +julia> print_version() +``` +""" +function print_version() + @printf( "TAP version 13\n" ); +end + +""" + print_summary( total, passing ) + +Print the benchmark summary. + +# Arguments + +* `total`: total number of tests +* `passing`: number of passing tests + +# Examples + +``` julia +julia> print_summary( 3, 3 ) +``` +""" +function print_summary( total, passing ) + @printf( "#\n" ); + @printf( "1..%d\n", total ); # TAP plan + @printf( "# total %d\n", total ); + @printf( "# pass %d\n", passing ); + @printf( "#\n" ); + @printf( "# ok\n" ); +end + +""" + print_results( iterations, elapsed ) + +Print benchmark results. + +# Arguments + +* `iterations`: number of iterations +* `elapsed`: elapsed time (in seconds) + +# Examples + +``` julia +julia> print_results( 1000000, 0.131009101868 ) +``` +""" +function print_results( iterations, elapsed ) + rate = iterations / elapsed + + @printf( " ---\n" ); + @printf( " iterations: %d\n", iterations ); + @printf( " elapsed: %0.9f\n", elapsed ); + @printf( " rate: %0.9f\n", rate ); + @printf( " ...\n" ); +end + +""" + benchmark() + +Run a benchmark. + +# Notes + +* Benchmark results are returned as a two-element array: [ iterations, elapsed ]. +* The number of iterations is not the true number of iterations. Instead, an 'iteration' is defined as a 'sample', which is a computed estimate for a single evaluation. +* The elapsed time is in seconds. + +# Examples + +``` julia +julia> out = benchmark(); +``` +""" +function benchmark() + t = BenchmarkTools.@benchmark ComplexF32( rand(), rand() ) samples=1e6 + + # Compute the total "elapsed" time and convert from nanoseconds to seconds: + s = sum( t.times ) / 1.0e9; + + # Determine the number of "iterations": + iter = length( t.times ); + + # Return the results: + [ iter, s ]; +end + +""" + main() + +Run benchmarks. + +# Examples + +``` julia +julia> main(); +``` +""" +function main() + print_version(); + for i in 1:repeats + @printf( "# julia::%s\n", name ); + results = benchmark(); + print_results( results[ 1 ], results[ 2 ] ); + @printf( "ok %d benchmark finished\n", i ); + end + print_summary( repeats, repeats ); +end + +main(); diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/benchmark/python/benchmark.py b/lib/node_modules/@stdlib/complex/float32/ctor/benchmark/python/benchmark.py new file mode 100644 index 00000000000..5779ccb9748 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/benchmark/python/benchmark.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python +# +# @license Apache-2.0 +# +# Copyright (c) 2018 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. + +"""Benchmark complex.""" + +from __future__ import print_function +import timeit + +NAME = "complex64" +REPEATS = 3 +ITERATIONS = 1000000 + + +def print_version(): + """Print the TAP version.""" + print("TAP version 13") + + +def print_summary(total, passing): + """Print the benchmark summary. + + # Arguments + + * `total`: total number of tests + * `passing`: number of passing tests + + """ + print("#") + print("1.." + str(total)) # TAP plan + print("# total " + str(total)) + print("# pass " + str(passing)) + print("#") + print("# ok") + + +def print_results(elapsed): + """Print benchmark results. + + # Arguments + + * `elapsed`: elapsed time (in seconds) + + # Examples + + ``` python + python> print_results(0.131009101868) + ``` + """ + rate = ITERATIONS / elapsed + + print(" ---") + print(" iterations: " + str(ITERATIONS)) + print(" elapsed: " + str(elapsed)) + print(" rate: " + str(rate)) + print(" ...") + + +def benchmark(): + """Run the benchmark and print benchmark results.""" + setup = "from random import random;" + stmt = "z = complex(float(random()), float(random()))" + + t = timeit.Timer(stmt, setup=setup) + + print_version() + + for i in range(REPEATS): + print("# python::" + NAME) + elapsed = t.timeit(number=ITERATIONS) + print_results(elapsed) + print("ok " + str(i+1) + " benchmark finished") + + print_summary(REPEATS, REPEATS) + + +def main(): + """Run the benchmark.""" + benchmark() + + +if __name__ == "__main__": + main() diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/docs/repl.txt b/lib/node_modules/@stdlib/complex/float32/ctor/docs/repl.txt new file mode 100644 index 00000000000..8d594817244 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/docs/repl.txt @@ -0,0 +1,84 @@ + +{{alias}}( real, imag ) + 64-bit complex number constructor. + + Both the real and imaginary components are stored as single-precision + floating-point numbers. + + Parameters + ---------- + real: number + Real component. + + imag: number + Imaginary component. + + Returns + ------- + z: Complex64 + 64-bit complex number. + + z.re: number + Read-only property returning the real component. + + z.im: number + Read-only property returning the imaginary component. + + Examples + -------- + > var z = new {{alias}}( 5.0, 3.0 ) + + > z.re + 5.0 + > z.im + 3.0 + + +{{alias}}.BYTES_PER_ELEMENT + Size (in bytes) of each component. + + Returns + ------- + v: integer + Size (in bytes) of each component. + + Examples + -------- + > var s = {{alias}}.BYTES_PER_ELEMENT + 4 + + +{{alias}}.prototype.BYTES_PER_ELEMENT + Size (in bytes) of each component. + + Returns + ------- + s: integer + Size (in bytes) of each component. + + Examples + -------- + > var z = new {{alias}}( 5.0, 3.0 ) + + > var s = z.BYTES_PER_ELEMENT + 4 + + +{{alias}}.prototype.byteLength + Length (in bytes) of a complex number. + + Returns + ------- + len: integer + Length (in bytes) of a complex number. + + Examples + -------- + > var z = new {{alias}}( 5.0, 3.0 ) + + > var s = z.byteLength + 8 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/docs/types/index.d.ts b/lib/node_modules/@stdlib/complex/float32/ctor/docs/types/index.d.ts new file mode 100644 index 00000000000..ff617640276 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/docs/types/index.d.ts @@ -0,0 +1,111 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2021 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. +*/ + +// TypeScript Version: 4.1 + +/** +* 64-bit complex number. +*/ +declare class Complex64 { + /** + * 64-bit complex number constructor. + * + * @param real - real component + * @param imag - imaginary component + * @returns 64-bit complex number + * + * @example + * var z = new Complex64( 5.0, 3.0 ); + * // returns + */ + constructor( real: number, imag: number ); + + /** + * Read-only property returning the real component. + * + * @returns real component + */ + readonly re: number; + + /** + * Read-only property returning the imaginary component. + * + * @returns imaginary component + */ + readonly im: number; + + /** + * Size (in bytes) of each component. + * + * @returns size of each component + * + * @example + * var nbytes = Complex64.BYTES_PER_ELEMENT; + * // returns 4 + */ + readonly BYTES_PER_ELEMENT: 4; + + /** + * Length (in bytes) of a complex number. + * + * @returns byte length + * + * @example + * var z = new Complex64( 5.0, 3.0 ); + * + * var nbytes = z.byteLength; + * // returns 8 + */ + readonly byteLength: 8; + + /** + * Serializes a complex number as a string. + * + * @returns serialized complex number + * + * @example + * var z = new Complex64( 5.0, 3.0 ); + * + * var str = z.toString(); + * // returns '5 + 3i' + */ + toString(): string; + + /** + * Serializes a complex number as a JSON object. + * + * ## Notes + * + * - `JSON.stringify()` implicitly calls this method when stringifying a `Complex64` instance. + * + * + * @returns serialized complex number + * + * @example + * var z = new Complex64( 5.0, 3.0 ); + * + * var obj = z.toJSON(); + * // returns { 'type': 'Complex64', 're': 5.0, 'im': 3.0 } + */ + toJSON(): any; +} + + +// EXPORTS // + +export = Complex64; diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/docs/types/test.ts b/lib/node_modules/@stdlib/complex/float32/ctor/docs/types/test.ts new file mode 100644 index 00000000000..58e62c9c065 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/docs/types/test.ts @@ -0,0 +1,69 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2021 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. +*/ + +import Complex64 = require( './index' ); + + +// TESTS // + +// The function returns a 64-bit complex number with the expected properties... +{ + const x = new Complex64( 5.0, 3.0 ); // $ExpectType Complex64 + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + x.im; // $ExpectType number + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + x.re; // $ExpectType number + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + x.BYTES_PER_ELEMENT; // $ExpectType 4 + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + x.byteLength; // $ExpectType 8 +} + +// 64-bit complex number comes with a `toString` method to serialize a complex number as a string... +{ + const x = new Complex64( 5.0, 3.0 ); // $ExpectType Complex64 + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + x.toString(); // $ExpectType string +} + +// 64-bit complex number comes with a `toJSON` method to serialize a complex number as a JSON object.... +{ + const x = new Complex64( 5.0, 3.0 ); // $ExpectType Complex64 + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + x.toJSON(); // $ExpectType any +} + +// The compiler throws an error if the constructor is invoked without the `new` keyword... +{ + Complex64( 5.0, 3.0 ); // $ExpectError +} + +// The compiler throws an error if the constructor is provided an unsupported number of arguments... +{ + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + new Complex64( 5.0 ); // $ExpectError + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + new Complex64( 5.0, 3.0, 1.0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/examples/c/Makefile b/lib/node_modules/@stdlib/complex/float32/ctor/examples/c/Makefile new file mode 100644 index 00000000000..70c91f4e131 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2021 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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/examples/c/example.c b/lib/node_modules/@stdlib/complex/float32/ctor/examples/c/example.c new file mode 100644 index 00000000000..31b58f3938f --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/examples/c/example.c @@ -0,0 +1,73 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2021 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. +*/ + +#include "stdlib/complex/float32/ctor.h" +#include +#include + +/** +* Return the real component of a single-precision complex floating-point number. +* +* @param z complex number +* @return real component +*/ +static float real( const stdlib_complex64_t z ) { + stdlib_complex64_parts_t v; + + // Assign a single-precision complex floating-point number: + v.value = z; // cppcheck-suppress unreadVariable + + // Extract the real component: + float re = v.parts[ 0 ]; + + return re; +} + +/** +* Return the imaginary component of a single-precision complex floating-point number. +* +* @param z complex number +* @return imaginary component +*/ +static float imag( const stdlib_complex64_t z ) { + stdlib_complex64_parts_t v; + + // Assign a single-precision complex floating-point number: + v.value = z; // cppcheck-suppress unreadVariable + + // Extract the imaginary component: + float im = v.parts[ 1 ]; + + return im; +} + +int main( void ) { + const stdlib_complex64_t x[] = { + stdlib_complex64( 5.0f, 2.0f ), + stdlib_complex64( -2.0f, 1.0f ), + stdlib_complex64( 0.0f, -0.0f ), + stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f ) + }; + + stdlib_complex64_t v; + int i; + for ( i = 0; i < 4; i++ ) { + v = x[ i ]; + printf( "%f + %fi\n", real( v ), imag( v ) ); + } +} diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/examples/index.js b/lib/node_modules/@stdlib/complex/float32/ctor/examples/index.js new file mode 100644 index 00000000000..7f515037c9d --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/examples/index.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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'; + +var Complex64 = require( './../lib' ); + +var z = new Complex64( 3.0, -2.0 ); + +console.log( 'type: %s', typeof z ); +// => 'type: object' + +console.log( 'str: %s', z ); +// => 'str: 3 - 2i' + +console.log( 'real: %d', z.re ); +// => 'real: 3' + +console.log( 'imaginary: %d', z.im ); +// => 'imaginary: -2' + +console.log( 'JSON: %s', JSON.stringify( z ) ); +// => 'JSON: {"type":"Complex64","re":3,"im":-2}' diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/include/stdlib/complex/float32/ctor.h b/lib/node_modules/@stdlib/complex/float32/ctor/include/stdlib/complex/float32/ctor.h new file mode 100644 index 00000000000..a19097c5fd1 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/include/stdlib/complex/float32/ctor.h @@ -0,0 +1,148 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2021 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. +*/ + +#ifndef STDLIB_COMPLEX_FLOAT32_CTOR_H +#define STDLIB_COMPLEX_FLOAT32_CTOR_H + +#include +#include + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +// Check for C11 support where we can precisely define a complex number and thus avoid issues concerning infinities and NaNs as real and/or imaginary components... (TODO: revisit the following check; similar to NumPy, we may want to check for a compile time variable (e.g., STDLIB_USE_C99_COMPLEX), rather than checking for C11 support, especially if we are not using C11 functionality) +#if defined(_Imaginary_I) && defined(CMPLXF) + +/** +* An opaque type definition for a single-precision complex floating-point number. +*/ +typedef float complex stdlib_complex64_t; + +// If we aren't going to use the native complex number type, we need to define a complex number as an "opaque" struct (here, "opaque" meaning type consumers should **not** be accessing the components directly, but only through dedicated functions) for storing the real and imaginary components... +#else + +/** +* An opaque type definition for a single-precision complex floating-point number. +* +* @example +* stdlib_complex64_t z; +* +* // Set the real component: +* z.re = 5.0f; +* +* // Set the imaginary component: +* z.im = 2.0f; +*/ +typedef struct { + /** + * Real component. + */ + float re; + + /** + * Imaginary component. + */ + float im; +} stdlib_complex64_t; + +#endif + +/** +* An opaque type definition for a union for accessing the real and imaginary parts of a single-precision complex floating-point number. +* +* @example +* float realf( const stdlib_complex64_t z ) { +* stdlib_complex64_parts_t v; +* +* // Assign a single-precision complex floating-point number: +* v.value = z; +* +* // Extract the real component: +* float re = v.parts[ 0 ]; +* +* return re; +* } +* +* // ... +* +* // Create a complex number: +* stdlib_complex64_t z = stdlib_complex64( 5.0f, 2.0f ); +* +* // ... +* +* // Access the real component: +* float re = realf( z ); +* // returns 5.0f +*/ +typedef union { + // An opaque type for the output value (e.g., could be a `struct` or a C99 complex number): + stdlib_complex64_t value; + + // Leverage the fact that C99 specifies that complex numbers have the same representation and alignment as a two-element array (see ), where the first element is the real component and the second element is the imaginary component, thus allowing us to create a complex number irrespective of its native data type (e.g., `struct` vs `float complex`): + float parts[ 2 ]; +} stdlib_complex64_parts_t; + +/** +* Returns a single-precision complex floating-point number. +*/ +stdlib_complex64_t stdlib_complex64( const float real, const float imag ); + +/** +* Converts a single-precision floating-point number to a single-precision complex floating-point number. +*/ +stdlib_complex64_t stdlib_complex64_from_float32( const float real ); + +/** +* Converts a double-precision floating-point number to a single-precision complex floating-point number. +*/ +stdlib_complex64_t stdlib_complex64_from_float64( const double real ); + +/** +* Converts (copies) a single-precision complex floating-point number to a single-precision complex floating-point number. +*/ +stdlib_complex64_t stdlib_complex64_from_complex64( const stdlib_complex64_t z ); + +/** +* Converts a signed 8-bit integer to a single-precision complex floating-point number. +*/ +stdlib_complex64_t stdlib_complex64_from_int8( const int8_t real ); + +/** +* Converts an unsigned 8-bit integer to a single-precision complex floating-point number. +*/ +stdlib_complex64_t stdlib_complex64_from_uint8( const uint8_t real ); + +/** +* Converts a signed 16-bit integer to a single-precision complex floating-point number. +*/ +stdlib_complex64_t stdlib_complex64_from_int16( const int16_t real ); + +/** +* Converts an unsigned 16-bit integer to a single-precision complex floating-point number. +*/ +stdlib_complex64_t stdlib_complex64_from_uint16( const uint16_t real ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_COMPLEX_FLOAT32_CTOR_H diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/lib/index.js b/lib/node_modules/@stdlib/complex/float32/ctor/lib/index.js new file mode 100644 index 00000000000..45597b5e049 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/lib/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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'; + +/** +* 64-bit complex number constructor. +* +* @module @stdlib/complex/float32/ctor +* +* @example +* var Complex64 = require( '@stdlib/complex/float32/ctor' ); +* +* var z = new Complex64( 5.0, 3.0 ); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/lib/main.js b/lib/node_modules/@stdlib/complex/float32/ctor/lib/main.js new file mode 100644 index 00000000000..d0bc7892f7b --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/lib/main.js @@ -0,0 +1,159 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var defineProperty = require( '@stdlib/utils/define-property' ); +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var format = require( '@stdlib/string/format' ); +var toStr = require( './tostring.js' ); +var toJSON = require( './tojson.js' ); + + +// MAIN // + +/** +* 64-bit complex number constructor. +* +* @constructor +* @param {number} real - real component +* @param {number} imag - imaginary component +* @throws {TypeError} must invoke using the `new` keyword +* @throws {TypeError} real component must be a number +* @throws {TypeError} imaginary component must be a number +* @returns {Complex64} 64-bit complex number +* +* @example +* var z = new Complex64( 5.0, 3.0 ); +* // returns +*/ +function Complex64( real, imag ) { + if ( !( this instanceof Complex64 ) ) { + throw new TypeError( 'invalid invocation. Constructor must be called with the `new` keyword.' ); + } + if ( !isNumber( real ) ) { + throw new TypeError( format( 'invalid argument. Real component must be a number. Value: `%s`.', real ) ); + } + if ( !isNumber( imag ) ) { + throw new TypeError( format( 'invalid argument. Imaginary component must be a number. Value: `%s`.', imag ) ); + } + defineProperty( this, 're', { + 'configurable': false, + 'enumerable': true, + 'writable': false, + 'value': float64ToFloat32( real ) + }); + defineProperty( this, 'im', { + 'configurable': false, + 'enumerable': true, + 'writable': false, + 'value': float64ToFloat32( imag ) + }); + return this; +} + +/** +* Size (in bytes) of each component. +* +* @name BYTES_PER_ELEMENT +* @memberof Complex64 +* @type {integer} +* @returns {integer} size of each component +* +* @example +* var nbytes = Complex64.BYTES_PER_ELEMENT; +* // returns 4 +*/ +setReadOnly( Complex64, 'BYTES_PER_ELEMENT', 4 ); + +/** +* Size (in bytes) of each component. +* +* @name BYTES_PER_ELEMENT +* @memberof Complex64.prototype +* @type {integer} +* @returns {integer} size of each component +* +* @example +* var z = new Complex64( 5.0, 3.0 ); +* +* var nbytes = z.BYTES_PER_ELEMENT; +* // returns 4 +*/ +setReadOnly( Complex64.prototype, 'BYTES_PER_ELEMENT', 4 ); + +/** +* Length (in bytes) of a complex number. +* +* @name byteLength +* @memberof Complex64.prototype +* @type {integer} +* @returns {integer} byte length +* +* @example +* var z = new Complex64( 5.0, 3.0 ); +* +* var nbytes = z.byteLength; +* // returns 8 +*/ +setReadOnly( Complex64.prototype, 'byteLength', 8 ); + +/** +* Serializes a complex number as a string. +* +* @name toString +* @memberof Complex64.prototype +* @type {Function} +* @returns {string} serialized complex number +* +* @example +* var z = new Complex64( 5.0, 3.0 ); +* +* var str = z.toString(); +* // returns '5 + 3i' +*/ +setReadOnly( Complex64.prototype, 'toString', toStr ); + +/** +* Serializes a complex number as a JSON object. +* +* ## Notes +* +* - `JSON.stringify()` implicitly calls this method when stringifying a `Complex64` instance. +* +* @name toJSON +* @memberof Complex64.prototype +* @type {Function} +* @returns {Object} serialized complex number +* +* @example +* var z = new Complex64( 5.0, 3.0 ); +* +* var obj = z.toJSON(); +* // returns { 'type': 'Complex64', 're': 5.0, 'im': 3.0 } +*/ +setReadOnly( Complex64.prototype, 'toJSON', toJSON ); + + +// EXPORTS // + +module.exports = Complex64; diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/lib/tojson.js b/lib/node_modules/@stdlib/complex/float32/ctor/lib/tojson.js new file mode 100644 index 00000000000..79948378555 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/lib/tojson.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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'; + +/** +* Serializes a complex number as a JSON object. +* +* @private +* @returns {Object} JSON representation +*/ +function toJSON() { + /* eslint-disable no-invalid-this */ + var out = {}; + out.type = 'Complex64'; + out.re = this.re; + out.im = this.im; + return out; +} + + +// EXPORTS // + +module.exports = toJSON; diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/lib/tostring.js b/lib/node_modules/@stdlib/complex/float32/ctor/lib/tostring.js new file mode 100644 index 00000000000..d57bdc16ede --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/lib/tostring.js @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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'; + +/** +* Serializes a complex number as a string. +* +* @private +* @returns {string} serialized complex number +*/ +function toString() { // eslint-disable-line stdlib/no-redeclare + /* eslint-disable no-invalid-this */ + var str = '' + this.re; + if ( this.im < 0 ) { + str += ' - ' + (-this.im); + } else { + str += ' + ' + this.im; + } + str += 'i'; + return str; +} + + +// EXPORTS // + +module.exports = toString; diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/manifest.json b/lib/node_modules/@stdlib/complex/float32/ctor/manifest.json new file mode 100644 index 00000000000..890a937a3dc --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/manifest.json @@ -0,0 +1,38 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + } + ] +} diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/package.json b/lib/node_modules/@stdlib/complex/float32/ctor/package.json new file mode 100644 index 00000000000..d789199f657 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/complex/float32/ctor", + "version": "0.0.0", + "description": "64-bit complex number.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdtypes", + "types", + "data", + "structure", + "constructor", + "ctor", + "complex", + "complex64", + "64-bit", + "float32", + "float", + "single", + "single-precision", + "ieee754" + ] +} diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/src/main.c b/lib/node_modules/@stdlib/complex/float32/ctor/src/main.c new file mode 100644 index 00000000000..f1bfb9fb372 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/src/main.c @@ -0,0 +1,151 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2021 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. +*/ + +#include "stdlib/complex/float32/ctor.h" +#include + +/** +* Returns a single-precision complex floating-point number. +* +* @param real real component +* @param imag imaginary component +* @return single-precision complex floating-point number +* +* @example +* stdlib_complex64_t z = stdlib_complex64( 5.0f, 2.0f ); +*/ +stdlib_complex64_t stdlib_complex64( const float real, const float imag ) { + stdlib_complex64_parts_t z; + z.parts[ 0 ] = real; + z.parts[ 1 ] = imag; // cppcheck-suppress unreadVariable + return z.value; +} + +/** +* Converts a single-precision floating-point number to a single-precision complex floating-point number. +* +* @param real real component +* @return single-precision complex floating-point number +* +* @example +* stdlib_complex64_t z = stdlib_complex64_from_float32( 5.0f ); +*/ +stdlib_complex64_t stdlib_complex64_from_float32( const float real ) { + stdlib_complex64_parts_t z; + z.parts[ 0 ] = real; + z.parts[ 1 ] = 0.0f; // cppcheck-suppress unreadVariable + return z.value; +} + +/** +* Converts a double-precision floating-point number to a single-precision complex floating-point number. +* +* @param real real component +* @return single-precision complex floating-point number +* +* @example +* stdlib_complex64_t z = stdlib_complex64_from_float64( 5.0 ); +*/ +stdlib_complex64_t stdlib_complex64_from_float64( const double real ) { + stdlib_complex64_parts_t z; + z.parts[ 0 ] = (float)real; + z.parts[ 1 ] = 0.0f; // cppcheck-suppress unreadVariable + return z.value; +} + +/** +* Converts (copies) a single-precision complex floating-point number to a single-precision complex floating-point number. +* +* @param z single-precision complex floating-point number +* @return single-precision complex floating-point number +* +* @example +* stdlib_complex64_t z1 = stdlib_complex64( 5.0f, 3.0f ); +* stdlib_complex64_t z2 = stdlib_complex64_from_complex64( z1 ); +*/ +stdlib_complex64_t stdlib_complex64_from_complex64( const stdlib_complex64_t z ) { + stdlib_complex64_parts_t v1 = { z }; + stdlib_complex64_parts_t v2; + v2.parts[ 0 ] = v1.parts[ 0 ]; + v2.parts[ 1 ] = v1.parts[ 1 ]; // cppcheck-suppress unreadVariable + return v2.value; +} + +/** +* Converts a signed 8-bit integer to a single-precision complex floating-point number. +* +* @param real real component +* @return single-precision complex floating-point number +* +* @example +* stdlib_complex64_t z = stdlib_complex64_from_int8( 5 ); +*/ +stdlib_complex64_t stdlib_complex64_from_int8( const int8_t real ) { + stdlib_complex64_parts_t z; + z.parts[ 0 ] = (float)real; + z.parts[ 1 ] = 0.0f; // cppcheck-suppress unreadVariable + return z.value; +} + +/** +* Converts an unsigned 8-bit integer to a single-precision complex floating-point number. +* +* @param real real component +* @return single-precision complex floating-point number +* +* @example +* stdlib_complex64_t z = stdlib_complex64_from_uint8( 5 ); +*/ +stdlib_complex64_t stdlib_complex64_from_uint8( const uint8_t real ) { + stdlib_complex64_parts_t z; + z.parts[ 0 ] = (float)real; + z.parts[ 1 ] = 0.0f; // cppcheck-suppress unreadVariable + return z.value; +} + +/** +* Converts a signed 16-bit integer to a single-precision complex floating-point number. +* +* @param real real component +* @return single-precision complex floating-point number +* +* @example +* stdlib_complex64_t z = stdlib_complex64_from_int16( 5 ); +*/ +stdlib_complex64_t stdlib_complex64_from_int16( const int16_t real ) { + stdlib_complex64_parts_t z; + z.parts[ 0 ] = (float)real; + z.parts[ 1 ] = 0.0f; // cppcheck-suppress unreadVariable + return z.value; +} + +/** +* Converts an unsigned 16-bit integer to a single-precision complex floating-point number. +* +* @param real real component +* @return single-precision complex floating-point number +* +* @example +* stdlib_complex64_t z = stdlib_complex64_from_uint16( 5 ); +*/ +stdlib_complex64_t stdlib_complex64_from_uint16( const uint16_t real ) { + stdlib_complex64_parts_t z; + z.parts[ 0 ] = (float)real; + z.parts[ 1 ] = 0.0f; // cppcheck-suppress unreadVariable + return z.value; +} diff --git a/lib/node_modules/@stdlib/complex/float32/ctor/test/test.js b/lib/node_modules/@stdlib/complex/float32/ctor/test/test.js new file mode 100644 index 00000000000..f7962cf3ee5 --- /dev/null +++ b/lib/node_modules/@stdlib/complex/float32/ctor/test/test.js @@ -0,0 +1,213 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var Complex64 = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Complex64, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function is a constructor', function test( t ) { + var z = new Complex64( 5.0, 3.0 ); + t.strictEqual( z instanceof Complex64, true, 'is an instance' ); + t.end(); +}); + +tape( 'the constructor throws an error if provided a real component which is not a number', function test( t ) { + var values; + var i; + + values = [ + '5', + null, + void 0, + true, + false, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var z = new Complex64( value, 3.0 ); // eslint-disable-line no-unused-vars + }; + } +}); + +tape( 'the constructor throws an error if provided an imaginary component which is not a number', function test( t ) { + var values; + var i; + + values = [ + '5', + null, + void 0, + true, + false, + [], + {}, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var z = new Complex64( 5.0, value ); // eslint-disable-line no-unused-vars + }; + } +}); + +tape( 'the constructor requires the `new` keyword', function test( t ) { + var ctor = Complex64; + t.throws( foo, TypeError, 'throws an error' ); + t.end(); + + function foo() { + ctor( 5.0, 3.0 ); + } +}); + +tape( 'the constructor has a read-only `BYTES_PER_ELEMENT` property', function test( t ) { + t.strictEqual( hasOwnProp( Complex64, 'BYTES_PER_ELEMENT' ), true, 'has property' ); + t.strictEqual( Complex64.BYTES_PER_ELEMENT, 4, 'returns expected value' ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + Complex64.BYTES_PER_ELEMENT = 16; + } +}); + +tape( 'the constructor prototype has a read-only `BYTES_PER_ELEMENT` property', function test( t ) { + t.strictEqual( hasOwnProp( Complex64.prototype, 'BYTES_PER_ELEMENT' ), true, 'has property' ); + t.strictEqual( Complex64.prototype.BYTES_PER_ELEMENT, 4, 'returns expected value' ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + Complex64.prototype.BYTES_PER_ELEMENT = 16; + } +}); + +tape( 'the constructor prototype has a read-only `byteLength` property', function test( t ) { + t.strictEqual( hasOwnProp( Complex64.prototype, 'byteLength' ), true, 'has property' ); + t.strictEqual( Complex64.prototype.byteLength, 8, 'returns expected value' ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + Complex64.prototype.byteLength = 64; + } +}); + +tape( 'the constructor returns an instance having a property for getting the real component', function test( t ) { + var z = new Complex64( 5.0, 3.0 ); + t.strictEqual( z.re, 5.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance which throws an error when attempting to mutate the real component', function test( t ) { + var z = new Complex64( 5.0, 3.0 ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + z.re = -5.0; + } +}); + +tape( 'the constructor returns an instance having a property for getting the imaginary component', function test( t ) { + var z = new Complex64( 5.0, 3.0 ); + t.strictEqual( z.im, 3.0, 'returns expected value' ); + t.end(); +}); + +tape( 'the constructor returns an instance which throws an error when attempting to mutate the imaginary component', function test( t ) { + var z = new Complex64( 5.0, 3.0 ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + z.im = -3.0; + } +}); + +tape( 'the constructor returns an instance which stores real and imaginary components as single-precision floating-point numbers', function test( t ) { + var z = new Complex64( 3.14, -3.14 ); + + t.strictEqual( z.re, 3.140000104904175, 'stores as single-precision' ); + t.strictEqual( z.im, -3.140000104904175, 'stores as single-precision' ); + + t.end(); +}); + +tape( 'the constructor returns an instance which supports serializing an instance as a string', function test( t ) { + var z; + + z = new Complex64( 5.0, -3.0 ); + t.strictEqual( z.toString(), '5 - 3i', 'returns expected value' ); + + z = new Complex64( 5.0, 3.0 ); + t.strictEqual( z.toString(), '5 + 3i', 'returns expected value' ); + + t.end(); +}); + +tape( 'the constructor returns an instance which supports serializing an instance as a JSON object', function test( t ) { + var expected; + var z; + + z = new Complex64( 5.0, -3.0 ); + expected = { + 'type': 'Complex64', + 're': 5.0, + 'im': -3.0 + }; + t.deepEqual( z.toJSON(), expected, 'returns expected value' ); + t.strictEqual( JSON.stringify( z ), JSON.stringify( expected ), 'serializes as JSON when called by JSON.stringify()' ); + + z = new Complex64( 5.0, 3.0 ); + expected = { + 'type': 'Complex64', + 're': 5.0, + 'im': 3.0 + }; + t.deepEqual( z.toJSON(), expected, 'returns expected value' ); + t.strictEqual( JSON.stringify( z ), JSON.stringify( expected ), 'serializes as JSON when called by JSON.stringify()' ); + + t.end(); +});