@stdlib/complex-float32 0.0.6 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,9 +18,20 @@ limitations under the License.
18
18
 
19
19
  -->
20
20
 
21
+
22
+ <details>
23
+ <summary>
24
+ About stdlib...
25
+ </summary>
26
+ <p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
27
+ <p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
28
+ <p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
29
+ <p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
30
+ </details>
31
+
21
32
  # Complex64
22
33
 
23
- [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] [![dependencies][dependencies-image]][dependencies-url]
34
+ [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
24
35
 
25
36
  > 64-bit complex number.
26
37
 
@@ -197,25 +208,311 @@ var Complex64 = require( '@stdlib/complex-float32' );
197
208
  var z = new Complex64( 3.0, -2.0 );
198
209
 
199
210
  console.log( 'type: %s', typeof z );
200
- // => type: object
211
+ // => 'type: object'
201
212
 
202
213
  console.log( 'str: %s', z );
203
- // => str: 3 - 2i
214
+ // => 'str: 3 - 2i'
204
215
 
205
216
  console.log( 'real: %d', z.re );
206
- // => real: 3.0
217
+ // => 'real: 3'
207
218
 
208
219
  console.log( 'imag: %d', z.im );
209
- // => imag: -2.0
220
+ // => 'imag: -2'
210
221
 
211
222
  console.log( 'JSON: %s', JSON.stringify( z ) );
212
- // => JSON: {"type":"Complex64","re":3,"im":-2}
223
+ // => 'JSON: {"type":"Complex64","re":3,"im":-2}'
224
+ ```
225
+
226
+ </section>
227
+
228
+ <!-- /.examples -->
229
+
230
+ <!-- C interface documentation. -->
231
+
232
+ * * *
233
+
234
+ <section class="c">
235
+
236
+ ## C APIs
237
+
238
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
239
+
240
+ <section class="intro">
241
+
242
+ </section>
243
+
244
+ <!-- /.intro -->
245
+
246
+ <!-- C usage documentation. -->
247
+
248
+ <section class="usage">
249
+
250
+ ### Usage
251
+
252
+ ```c
253
+ #include "stdlib/complex/float32.h"
254
+ ```
255
+
256
+ #### stdlib_complex64_t
257
+
258
+ An opaque type definition for a single-precision complex floating-point number.
259
+
260
+ ```c
261
+ stdlib_complex64_t z = stdlib_complex64( 5.0f, 2.0f );
262
+ ```
263
+
264
+ #### stdlib_complex64_parts_t
265
+
266
+ An opaque type definition for a union for accessing the real and imaginary parts of a single-precision complex floating-point number.
267
+
268
+ ```c
269
+ float realf( const stdlib_complex64_t z ) {
270
+ stdlib_complex64_parts_t v;
271
+
272
+ // Assign a single-precision complex floating-point number:
273
+ v.value = z;
274
+
275
+ // Extract the real component:
276
+ float re = v.parts[ 0 ];
277
+
278
+ return re;
279
+ }
280
+
281
+ // ...
282
+
283
+ // Create a complex number:
284
+ stdlib_complex64_t z = stdlib_complex64( 5.0f, 2.0f );
285
+
286
+ // ...
287
+
288
+ // Access the real component:
289
+ float re = realf( z );
290
+ // returns 5.0f
291
+ ```
292
+
293
+ The union has the following members:
294
+
295
+ - **value**: `stdlib_complex64_t` single-precision complex floating-point number.
296
+
297
+ - **parts**: `float[]` array having the following elements:
298
+
299
+ - **0**: `float` real component.
300
+ - **1**: `float` imaginary component.
301
+
302
+ #### stdlib_complex64( real, imag )
303
+
304
+ Returns a single-precision complex floating-point number.
305
+
306
+ ```c
307
+ stdlib_complex64_t z = stdlib_complex64( 5.0f, 2.0f );
308
+ ```
309
+
310
+ The function accepts the following arguments:
311
+
312
+ - **real**: `[in] float` real component.
313
+ - **imag**: `[in] float` imaginary component.
314
+
315
+ ```c
316
+ stdlib_complex64_t stdlib_complex64( const float real, const float imag );
317
+ ```
318
+
319
+ #### stdlib_complex64_from_float32( real )
320
+
321
+ Converts a single-precision floating-point number to a single-precision complex floating-point number.
322
+
323
+ ```c
324
+ stdlib_complex64_t z = stdlib_complex64_from_float32( 5.0f );
325
+ ```
326
+
327
+ The function accepts the following arguments:
328
+
329
+ - **real**: `[in] float` real component.
330
+
331
+ ```c
332
+ stdlib_complex64_t stdlib_complex64_from_float32( const float real );
333
+ ```
334
+
335
+ #### stdlib_complex64_from_float64( real )
336
+
337
+ Converts a double-precision floating-point number to a single-precision complex floating-point number.
338
+
339
+ ```c
340
+ stdlib_complex64_t z = stdlib_complex64_from_float64( 5.0 );
341
+ ```
342
+
343
+ The function accepts the following arguments:
344
+
345
+ - **real**: `[in] double` real component.
346
+
347
+ ```c
348
+ stdlib_complex64_t stdlib_complex64_from_float64( const double real );
349
+ ```
350
+
351
+ #### stdlib_complex64_from_complex64( z )
352
+
353
+ Converts (copies) a single-precision complex floating-point number to a single-precision complex floating-point number.
354
+
355
+ ```c
356
+ stdlib_complex64_t z1 = stdlib_complex64( 5.0f, 3.0f );
357
+ stdlib_complex64_t z2 = stdlib_complex64_from_complex64( z1 );
358
+ ```
359
+
360
+ The function accepts the following arguments:
361
+
362
+ - **z**: `[in] stdlib_complex64_t` single-precision complex floating-point number.
363
+
364
+ ```c
365
+ stdlib_complex64_t stdlib_complex64_from_complex64( const stdlib_complex64_t z );
366
+ ```
367
+
368
+ #### stdlib_complex64_from_int8( real )
369
+
370
+ Converts a signed 8-bit integer to a single-precision complex floating-point number.
371
+
372
+ ```c
373
+ stdlib_complex64_t z = stdlib_complex64_from_int8( 5 );
374
+ ```
375
+
376
+ The function accepts the following arguments:
377
+
378
+ - **real**: `[in] int8_t` real component.
379
+
380
+ ```c
381
+ stdlib_complex64_t stdlib_complex64_from_int8( const int8_t real );
382
+ ```
383
+
384
+ #### stdlib_complex64_from_uint8( real )
385
+
386
+ Converts an unsigned 8-bit integer to a single-precision complex floating-point number.
387
+
388
+ ```c
389
+ stdlib_complex64_t z = stdlib_complex64_from_uint8( 5 );
390
+ ```
391
+
392
+ The function accepts the following arguments:
393
+
394
+ - **real**: `[in] uint8_t` real component.
395
+
396
+ ```c
397
+ stdlib_complex64_t stdlib_complex64_from_uint8( const uint8_t real );
398
+ ```
399
+
400
+ #### stdlib_complex64_from_int16( real )
401
+
402
+ Converts a signed 16-bit integer to a single-precision complex floating-point number.
403
+
404
+ ```c
405
+ stdlib_complex64_t z = stdlib_complex64_from_int16( 5 );
406
+ ```
407
+
408
+ The function accepts the following arguments:
409
+
410
+ - **real**: `[in] int16_t` real component.
411
+
412
+ ```c
413
+ stdlib_complex64_t stdlib_complex64_from_int16( const int16_t real );
414
+ ```
415
+
416
+ #### stdlib_complex64_from_uint16( real )
417
+
418
+ Converts an unsigned 16-bit integer to a single-precision complex floating-point number.
419
+
420
+ ```c
421
+ stdlib_complex64_t z = stdlib_complex64_from_uint16( 5 );
422
+ ```
423
+
424
+ The function accepts the following arguments:
425
+
426
+ - **real**: `[in] uint16_t` real component.
427
+
428
+ ```c
429
+ stdlib_complex64_t stdlib_complex64_from_uint16( const uint16_t real );
430
+ ```
431
+
432
+ </section>
433
+
434
+ <!-- /.usage -->
435
+
436
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
437
+
438
+ <section class="notes">
439
+
440
+ </section>
441
+
442
+ <!-- /.notes -->
443
+
444
+ <!-- C API usage examples. -->
445
+
446
+ <section class="examples">
447
+
448
+ ### Examples
449
+
450
+ ```c
451
+ #include "stdlib/complex/float32.h"
452
+ #include <stdint.h>
453
+ #include <stdio.h>
454
+
455
+ /**
456
+ * Return the real component of a single-precision complex floating-point number.
457
+ *
458
+ * @param z complex number
459
+ * @return real component
460
+ */
461
+ static float real( const stdlib_complex64_t z ) {
462
+ stdlib_complex64_parts_t v;
463
+
464
+ // Assign a single-precision complex floating-point number:
465
+ v.value = z;
466
+
467
+ // Extract the real component:
468
+ float re = v.parts[ 0 ];
469
+
470
+ return re;
471
+ }
472
+
473
+ /**
474
+ * Return the imaginary component of a single-precision complex floating-point number.
475
+ *
476
+ * @param z complex number
477
+ * @return imaginary component
478
+ */
479
+ static float imag( const stdlib_complex64_t z ) {
480
+ stdlib_complex64_parts_t v;
481
+
482
+ // Assign a single-precision complex floating-point number:
483
+ v.value = z;
484
+
485
+ // Extract the imaginary component:
486
+ float im = v.parts[ 1 ];
487
+
488
+ return im;
489
+ }
490
+
491
+ int main( void ) {
492
+ const stdlib_complex64_t x[] = {
493
+ stdlib_complex64( 5.0f, 2.0f ),
494
+ stdlib_complex64( -2.0f, 1.0f ),
495
+ stdlib_complex64( 0.0f, -0.0f ),
496
+ stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f )
497
+ };
498
+
499
+ stdlib_complex64_t v;
500
+ int i;
501
+ for ( i = 0; i < 4; i++ ) {
502
+ v = x[ i ];
503
+ printf( "%f + %fi\n", real( v ), imag( v ) );
504
+ }
505
+ }
213
506
  ```
214
507
 
215
508
  </section>
216
509
 
217
510
  <!-- /.examples -->
218
511
 
512
+ </section>
513
+
514
+ <!-- /.c -->
515
+
219
516
  <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
220
517
 
221
518
  <section class="references">
@@ -224,6 +521,21 @@ console.log( 'JSON: %s', JSON.stringify( z ) );
224
521
 
225
522
  <!-- /.references -->
226
523
 
524
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
525
+
526
+ <section class="related">
527
+
528
+ * * *
529
+
530
+ ## See Also
531
+
532
+ - <span class="package-name">[`@stdlib/complex-cmplx`][@stdlib/complex/cmplx]</span><span class="delimiter">: </span><span class="description">create a complex number.</span>
533
+ - <span class="package-name">[`@stdlib/complex-float64`][@stdlib/complex/float64]</span><span class="delimiter">: </span><span class="description">128-bit complex number.</span>
534
+
535
+ </section>
536
+
537
+ <!-- /.related -->
538
+
227
539
  <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
228
540
 
229
541
 
@@ -250,7 +562,7 @@ See [LICENSE][stdlib-license].
250
562
 
251
563
  ## Copyright
252
564
 
253
- Copyright &copy; 2016-2021. The Stdlib [Authors][stdlib-authors].
565
+ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
254
566
 
255
567
  </section>
256
568
 
@@ -263,22 +575,34 @@ Copyright &copy; 2016-2021. The Stdlib [Authors][stdlib-authors].
263
575
  [npm-image]: http://img.shields.io/npm/v/@stdlib/complex-float32.svg
264
576
  [npm-url]: https://npmjs.org/package/@stdlib/complex-float32
265
577
 
266
- [test-image]: https://github.com/stdlib-js/complex-float32/actions/workflows/test.yml/badge.svg
267
- [test-url]: https://github.com/stdlib-js/complex-float32/actions/workflows/test.yml
578
+ [test-image]: https://github.com/stdlib-js/complex-float32/actions/workflows/test.yml/badge.svg?branch=v0.1.0
579
+ [test-url]: https://github.com/stdlib-js/complex-float32/actions/workflows/test.yml?query=branch:v0.1.0
268
580
 
269
581
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/complex-float32/main.svg
270
582
  [coverage-url]: https://codecov.io/github/stdlib-js/complex-float32?branch=main
271
583
 
584
+ <!--
585
+
272
586
  [dependencies-image]: https://img.shields.io/david/stdlib-js/complex-float32.svg
273
587
  [dependencies-url]: https://david-dm.org/stdlib-js/complex-float32/main
274
588
 
589
+ -->
590
+
275
591
  [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
276
- [chat-url]: https://gitter.im/stdlib-js/stdlib/
592
+ [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
277
593
 
278
594
  [stdlib]: https://github.com/stdlib-js/stdlib
279
595
 
280
596
  [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
281
597
 
598
+ [umd]: https://github.com/umdjs/umd
599
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
600
+
601
+ [deno-url]: https://github.com/stdlib-js/complex-float32/tree/deno
602
+ [umd-url]: https://github.com/stdlib-js/complex-float32/tree/umd
603
+ [esm-url]: https://github.com/stdlib-js/complex-float32/tree/esm
604
+ [branches-url]: https://github.com/stdlib-js/complex-float32/blob/main/branches.md
605
+
282
606
  [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/complex-float32/main/LICENSE
283
607
 
284
608
  [json]: http://www.json.org/
@@ -289,6 +613,14 @@ Copyright &copy; 2016-2021. The Stdlib [Authors][stdlib-authors].
289
613
 
290
614
  [@stdlib/complex/reviver-float32]: https://www.npmjs.com/package/@stdlib/complex-reviver-float32
291
615
 
616
+ <!-- <related-links> -->
617
+
618
+ [@stdlib/complex/cmplx]: https://www.npmjs.com/package/@stdlib/complex-cmplx
619
+
620
+ [@stdlib/complex/float64]: https://www.npmjs.com/package/@stdlib/complex-float64
621
+
622
+ <!-- </related-links> -->
623
+
292
624
  </section>
293
625
 
294
626
  <!-- /.links -->
@@ -0,0 +1,3 @@
1
+ /// <reference path="../docs/types/index.d.ts" />
2
+ import Complex64 from '../docs/types/index';
3
+ export = Complex64;
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var a=o(function(S,n){
2
+ function c(){var e=""+this.re;return this.im<0?e+=" - "+-this.im:e+=" + "+this.im,e+="i",e}n.exports=c
3
+ });var u=o(function(T,s){
4
+ function b(){var e={};return e.type="Complex64",e.re=this.re,e.im=this.im,e}s.exports=b
5
+ });var h=o(function(d,v){
6
+ var l=require('@stdlib/assert-is-number/dist').isPrimitive,m=require('@stdlib/utils-define-property/dist'),i=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),p=require('@stdlib/number-float64-base-to-float32/dist'),f=require('@stdlib/error-tools-fmtprodmsg/dist'),y=a(),E=u();function t(e,r){if(!(this instanceof t))throw new TypeError(format('0Gp0G'));if(!l(e))throw new TypeError(f('0Gp3e',e));if(!l(r))throw new TypeError(f('0Gp3f',r));return m(this,"re",{configurable:!1,enumerable:!0,writable:!1,value:p(e)}),m(this,"im",{configurable:!1,enumerable:!0,writable:!1,value:p(r)}),this}i(t,"BYTES_PER_ELEMENT",4);i(t.prototype,"BYTES_PER_ELEMENT",4);i(t.prototype,"byteLength",8);i(t.prototype,"toString",y);i(t.prototype,"toJSON",E);v.exports=t
7
+ });var w=h();module.exports=w;
8
+ /** @license Apache-2.0 */
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../lib/tostring.js", "../lib/tojson.js", "../lib/main.js", "../lib/index.js"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serializes a complex number as a string.\n*\n* @private\n* @returns {string} serialized complex number\n*/\nfunction toString() { // eslint-disable-line stdlib/no-redeclare\n\t/* eslint-disable no-invalid-this */\n\tvar str = '' + this.re;\n\tif ( this.im < 0 ) {\n\t\tstr += ' - ' + (-this.im);\n\t} else {\n\t\tstr += ' + ' + this.im;\n\t}\n\tstr += 'i';\n\treturn str;\n}\n\n\n// EXPORTS //\n\nmodule.exports = toString;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Serializes a complex number as a JSON object.\n*\n* @private\n* @returns {Object} JSON representation\n*/\nfunction toJSON() {\n\t/* eslint-disable no-invalid-this */\n\tvar out = {};\n\tout.type = 'Complex64';\n\tout.re = this.re;\n\tout.im = this.im;\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = toJSON;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;\nvar defineProperty = require( '@stdlib/utils-define-property' );\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar float64ToFloat32 = require( '@stdlib/number-float64-base-to-float32' );\nvar format = require( '@stdlib/string-format' );\nvar toStr = require( './tostring.js' );\nvar toJSON = require( './tojson.js' );\n\n\n// MAIN //\n\n/**\n* 64-bit complex number constructor.\n*\n* @constructor\n* @param {number} real - real component\n* @param {number} imag - imaginary component\n* @throws {TypeError} must invoke using the `new` keyword\n* @throws {TypeError} real component must be a number\n* @throws {TypeError} imaginary component must be a number\n* @returns {Complex64} 64-bit complex number\n*\n* @example\n* var z = new Complex64( 5.0, 3.0 );\n* // returns <Complex64>\n*/\nfunction Complex64( real, imag ) {\n\tif ( !( this instanceof Complex64 ) ) {\n\t\tthrow new TypeError( 'invalid invocation. Constructor must be called with the `new` keyword.' );\n\t}\n\tif ( !isNumber( real ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Real component must be a number. Value: `%s`.', real ) );\n\t}\n\tif ( !isNumber( imag ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Imaginary component must be a number. Value: `%s`.', imag ) );\n\t}\n\tdefineProperty( this, 're', {\n\t\t'configurable': false,\n\t\t'enumerable': true,\n\t\t'writable': false,\n\t\t'value': float64ToFloat32( real )\n\t});\n\tdefineProperty( this, 'im', {\n\t\t'configurable': false,\n\t\t'enumerable': true,\n\t\t'writable': false,\n\t\t'value': float64ToFloat32( imag )\n\t});\n\treturn this;\n}\n\n/**\n* Size (in bytes) of each component.\n*\n* @name BYTES_PER_ELEMENT\n* @memberof Complex64\n* @type {integer}\n* @returns {integer} size of each component\n*\n* @example\n* var nbytes = Complex64.BYTES_PER_ELEMENT;\n* // returns 4\n*/\nsetReadOnly( Complex64, 'BYTES_PER_ELEMENT', 4 );\n\n/**\n* Size (in bytes) of each component.\n*\n* @name BYTES_PER_ELEMENT\n* @memberof Complex64.prototype\n* @type {integer}\n* @returns {integer} size of each component\n*\n* @example\n* var z = new Complex64( 5.0, 3.0 );\n*\n* var nbytes = z.BYTES_PER_ELEMENT;\n* // returns 4\n*/\nsetReadOnly( Complex64.prototype, 'BYTES_PER_ELEMENT', 4 );\n\n/**\n* Length (in bytes) of a complex number.\n*\n* @name byteLength\n* @memberof Complex64.prototype\n* @type {integer}\n* @returns {integer} byte length\n*\n* @example\n* var z = new Complex64( 5.0, 3.0 );\n*\n* var nbytes = z.byteLength;\n* // returns 8\n*/\nsetReadOnly( Complex64.prototype, 'byteLength', 8 );\n\n/**\n* Serializes a complex number as a string.\n*\n* @name toString\n* @memberof Complex64.prototype\n* @type {Function}\n* @returns {string} serialized complex number\n*\n* @example\n* var z = new Complex64( 5.0, 3.0 );\n*\n* var str = z.toString();\n* // returns '5 + 3i'\n*/\nsetReadOnly( Complex64.prototype, 'toString', toStr );\n\n/**\n* Serializes a complex number as a JSON object.\n*\n* ## Notes\n*\n* - `JSON.stringify()` implicitly calls this method when stringifying a `Complex64` instance.\n*\n* @name toJSON\n* @memberof Complex64.prototype\n* @type {Function}\n* @returns {Object} serialized complex number\n*\n* @example\n* var z = new Complex64( 5.0, 3.0 );\n*\n* var obj = z.toJSON();\n* // returns { 'type': 'Complex64', 're': 5.0, 'im': 3.0 }\n*/\nsetReadOnly( Complex64.prototype, 'toJSON', toJSON );\n\n\n// EXPORTS //\n\nmodule.exports = Complex64;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* 64-bit complex number constructor.\n*\n* @module @stdlib/complex-float32\n*\n* @example\n* var Complex64 = require( '@stdlib/complex-float32' );\n*\n* var z = new Complex64( 5.0, 3.0 );\n* // returns <Complex64>\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA0BA,SAASC,GAAW,CAEnB,IAAIC,EAAM,GAAK,KAAK,GACpB,OAAK,KAAK,GAAK,EACdA,GAAO,MAAS,CAAC,KAAK,GAEtBA,GAAO,MAAQ,KAAK,GAErBA,GAAO,IACAA,CACR,CAKAF,EAAO,QAAUC,ICzCjB,IAAAE,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA0BA,SAASC,GAAS,CAEjB,IAAIC,EAAM,CAAC,EACX,OAAAA,EAAI,KAAO,YACXA,EAAI,GAAK,KAAK,GACdA,EAAI,GAAK,KAAK,GACPA,CACR,CAKAF,EAAO,QAAUC,ICtCjB,IAAAE,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,0BAA2B,EAAE,YACjDC,EAAiB,QAAS,+BAAgC,EAC1DC,EAAc,QAAS,uDAAwD,EAC/EC,EAAmB,QAAS,wCAAyC,EACrEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAQ,IACRC,EAAS,IAoBb,SAASC,EAAWC,EAAMC,EAAO,CAChC,GAAK,EAAG,gBAAgBF,GACvB,MAAM,IAAI,UAAW,wEAAyE,EAE/F,GAAK,CAACP,EAAUQ,CAAK,EACpB,MAAM,IAAI,UAAWJ,EAAQ,kEAAmEI,CAAK,CAAE,EAExG,GAAK,CAACR,EAAUS,CAAK,EACpB,MAAM,IAAI,UAAWL,EAAQ,uEAAwEK,CAAK,CAAE,EAE7G,OAAAR,EAAgB,KAAM,KAAM,CAC3B,aAAgB,GAChB,WAAc,GACd,SAAY,GACZ,MAASE,EAAkBK,CAAK,CACjC,CAAC,EACDP,EAAgB,KAAM,KAAM,CAC3B,aAAgB,GAChB,WAAc,GACd,SAAY,GACZ,MAASE,EAAkBM,CAAK,CACjC,CAAC,EACM,IACR,CAcAP,EAAaK,EAAW,oBAAqB,CAAE,EAgB/CL,EAAaK,EAAU,UAAW,oBAAqB,CAAE,EAgBzDL,EAAaK,EAAU,UAAW,aAAc,CAAE,EAgBlDL,EAAaK,EAAU,UAAW,WAAYF,CAAM,EAoBpDH,EAAaK,EAAU,UAAW,SAAUD,CAAO,EAKnDP,EAAO,QAAUQ,IC5HjB,IAAIG,EAAO,IAKX,OAAO,QAAUA",
6
+ "names": ["require_tostring", "__commonJSMin", "exports", "module", "toString", "str", "require_tojson", "__commonJSMin", "exports", "module", "toJSON", "out", "require_main", "__commonJSMin", "exports", "module", "isNumber", "defineProperty", "setReadOnly", "float64ToFloat32", "format", "toStr", "toJSON", "Complex64", "real", "imag", "main"]
7
+ }
@@ -16,7 +16,7 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
- // TypeScript Version: 2.0
19
+ // TypeScript Version: 4.1
20
20
 
21
21
  /**
22
22
  * 64-bit complex number.
@@ -58,7 +58,7 @@ declare class Complex64 {
58
58
  * var nbytes = Complex64.BYTES_PER_ELEMENT;
59
59
  * // returns 4
60
60
  */
61
- readonly BYTES_PER_ELEMENT: number;
61
+ readonly BYTES_PER_ELEMENT: 4;
62
62
 
63
63
  /**
64
64
  * Length (in bytes) of a complex number.
@@ -71,7 +71,7 @@ declare class Complex64 {
71
71
  * var nbytes = z.byteLength;
72
72
  * // returns 8
73
73
  */
74
- readonly byteLength: number;
74
+ readonly byteLength: 8;
75
75
 
76
76
  /**
77
77
  * Serializes a complex number as a string.
@@ -0,0 +1,148 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2021 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #ifndef STDLIB_COMPLEX_FLOAT32_H
20
+ #define STDLIB_COMPLEX_FLOAT32_H
21
+
22
+ #include <complex.h>
23
+ #include <stdint.h>
24
+
25
+ /*
26
+ * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
27
+ */
28
+ #ifdef __cplusplus
29
+ extern "C" {
30
+ #endif
31
+
32
+ // 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)
33
+ #if defined(_Imaginary_I) && defined(CMPLXF)
34
+
35
+ /**
36
+ * An opaque type definition for a single-precision complex floating-point number.
37
+ */
38
+ typedef float complex stdlib_complex64_t;
39
+
40
+ // 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...
41
+ #else
42
+
43
+ /**
44
+ * An opaque type definition for a single-precision complex floating-point number.
45
+ *
46
+ * @example
47
+ * stdlib_complex64_t z;
48
+ *
49
+ * // Set the real component:
50
+ * z.re = 5.0f;
51
+ *
52
+ * // Set the imaginary component:
53
+ * z.im = 2.0f;
54
+ */
55
+ typedef struct {
56
+ /**
57
+ * Real component.
58
+ */
59
+ float re;
60
+
61
+ /**
62
+ * Imaginary component.
63
+ */
64
+ float im;
65
+ } stdlib_complex64_t;
66
+
67
+ #endif
68
+
69
+ /**
70
+ * An opaque type definition for a union for accessing the real and imaginary parts of a single-precision complex floating-point number.
71
+ *
72
+ * @example
73
+ * float realf( const stdlib_complex64_t z ) {
74
+ * stdlib_complex64_parts_t v;
75
+ *
76
+ * // Assign a single-precision complex floating-point number:
77
+ * v.value = z;
78
+ *
79
+ * // Extract the real component:
80
+ * float re = v.parts[ 0 ];
81
+ *
82
+ * return re;
83
+ * }
84
+ *
85
+ * // ...
86
+ *
87
+ * // Create a complex number:
88
+ * stdlib_complex64_t z = stdlib_complex64( 5.0f, 2.0f );
89
+ *
90
+ * // ...
91
+ *
92
+ * // Access the real component:
93
+ * float re = realf( z );
94
+ * // returns 5.0f
95
+ */
96
+ typedef union {
97
+ // An opaque type for the output value (e.g., could be a `struct` or a C99 complex number):
98
+ stdlib_complex64_t value;
99
+
100
+ // Leverage the fact that C99 specifies that complex numbers have the same representation and alignment as a two-element array (see <https://en.cppreference.com/w/c/language/arithmetic_types#Complex_floating_types>), 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`):
101
+ float parts[ 2 ];
102
+ } stdlib_complex64_parts_t;
103
+
104
+ /**
105
+ * Returns a single-precision complex floating-point number.
106
+ */
107
+ stdlib_complex64_t stdlib_complex64( const float real, const float imag );
108
+
109
+ /**
110
+ * Converts a single-precision floating-point number to a single-precision complex floating-point number.
111
+ */
112
+ stdlib_complex64_t stdlib_complex64_from_float32( const float real );
113
+
114
+ /**
115
+ * Converts a double-precision floating-point number to a single-precision complex floating-point number.
116
+ */
117
+ stdlib_complex64_t stdlib_complex64_from_float64( const double real );
118
+
119
+ /**
120
+ * Converts (copies) a single-precision complex floating-point number to a single-precision complex floating-point number.
121
+ */
122
+ stdlib_complex64_t stdlib_complex64_from_complex64( const stdlib_complex64_t z );
123
+
124
+ /**
125
+ * Converts a signed 8-bit integer to a single-precision complex floating-point number.
126
+ */
127
+ stdlib_complex64_t stdlib_complex64_from_int8( const int8_t real );
128
+
129
+ /**
130
+ * Converts an unsigned 8-bit integer to a single-precision complex floating-point number.
131
+ */
132
+ stdlib_complex64_t stdlib_complex64_from_uint8( const uint8_t real );
133
+
134
+ /**
135
+ * Converts a signed 16-bit integer to a single-precision complex floating-point number.
136
+ */
137
+ stdlib_complex64_t stdlib_complex64_from_int16( const int16_t real );
138
+
139
+ /**
140
+ * Converts an unsigned 16-bit integer to a single-precision complex floating-point number.
141
+ */
142
+ stdlib_complex64_t stdlib_complex64_from_uint16( const uint16_t real );
143
+
144
+ #ifdef __cplusplus
145
+ }
146
+ #endif
147
+
148
+ #endif // !STDLIB_COMPLEX_FLOAT32_H
package/lib/index.js CHANGED
@@ -32,9 +32,9 @@
32
32
 
33
33
  // MODULES //
34
34
 
35
- var Complex64 = require( './complex64.js' );
35
+ var main = require( './main.js' );
36
36
 
37
37
 
38
38
  // EXPORTS //
39
39
 
40
- module.exports = Complex64;
40
+ module.exports = main;