Gathering detailed insights and metrics for @stdlib/complex-float32-ctor
Gathering detailed insights and metrics for @stdlib/complex-float32-ctor
Gathering detailed insights and metrics for @stdlib/complex-float32-ctor
Gathering detailed insights and metrics for @stdlib/complex-float32-ctor
npm install @stdlib/complex-float32-ctor
Typescript
Module System
Min. Node Version
Node Version
NPM Version
C (57.48%)
JavaScript (42.52%)
Total Downloads
1,115,638
Last Day
15,385
Last Week
67,943
Last Month
289,253
Last Year
1,115,638
1 Stars
10 Commits
2 Watching
5 Branches
11 Contributors
Minified
Minified + Gzipped
Latest Version
0.0.2
Package Id
@stdlib/complex-float32-ctor@0.0.2
Unpacked Size
56.86 kB
Size
12.78 kB
File Count
16
NPM Version
8.19.4
Node Version
16.20.2
Publised On
27 Jul 2024
Cumulative downloads
Total Downloads
Last day
42.4%
15,385
Compared to previous day
Last week
-3.6%
67,943
Compared to previous week
Last month
34.1%
289,253
Compared to previous month
Last year
0%
1,115,638
Compared to previous year
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.
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.
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.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
64-bit complex number.
1npm install @stdlib/complex-float32-ctor
1var Complex64 = require( '@stdlib/complex-float32-ctor' );
64-bit complex number constructor, where real
and imag
are the real and imaginary components, respectively.
1var z = new Complex64( 5.0, 3.0 ); 2// returns <Complex64>
Size (in bytes) of each component.
1var nbytes = Complex64.BYTES_PER_ELEMENT; 2// returns 4
Size (in bytes) of each component.
1var z = new Complex64( 5.0, 3.0 ); 2 3var nbytes = z.BYTES_PER_ELEMENT; 4// returns 4
Length (in bytes) of a complex number.
1var z = new Complex64( 5.0, 3.0 ); 2 3var nbytes = z.byteLength; 4// returns 8
A Complex64
instance has the following properties...
A read-only property returning the real component.
1var z = new Complex64( 5.0, 3.0 ); 2 3var re = z.re; 4// returns 5.0
A read-only property returning the imaginary component.
1var z = new Complex64( 5.0, -3.0 ); 2 3var im = z.im; 4// returns -3.0
These methods do not mutate a Complex64
instance and, instead, return a complex number representation.
Returns a string
representation of a Complex64
instance.
1var z = new Complex64( 5.0, 3.0 ); 2var str = z.toString(); 3// returns '5 + 3i' 4 5z = new Complex64( -5.0, -3.0 ); 6str = z.toString(); 7// returns '-5 - 3i'
Returns a JSON representation of a Complex64
instance. JSON.stringify()
implicitly calls this method when stringifying a Complex64
instance.
1var z = new Complex64( 5.0, -3.0 ); 2 3var o = z.toJSON(); 4/* 5 { 6 "type": "Complex64", 7 "re": 5.0, 8 "im": -3.0 9 } 10*/
To revive a Complex64
number from a JSON string
, see @stdlib/complex/float32/reviver.
1var Complex64 = require( '@stdlib/complex-float32-ctor' ); 2 3var z = new Complex64( 3.0, -2.0 ); 4 5console.log( 'type: %s', typeof z ); 6// => 'type: object' 7 8console.log( 'str: %s', z ); 9// => 'str: 3 - 2i' 10 11console.log( 'real: %d', z.re ); 12// => 'real: 3' 13 14console.log( 'imaginary: %d', z.im ); 15// => 'imaginary: -2' 16 17console.log( 'JSON: %s', JSON.stringify( z ) ); 18// => 'JSON: {"type":"Complex64","re":3,"im":-2}'
1#include "stdlib/complex/float32/ctor.h"
An opaque type definition for a single-precision complex floating-point number.
1stdlib_complex64_t z = stdlib_complex64( 5.0f, 2.0f );
An opaque type definition for a union for accessing the real and imaginary parts of a single-precision complex floating-point number.
1float realf( const stdlib_complex64_t z ) { 2 stdlib_complex64_parts_t v; 3 4 // Assign a single-precision complex floating-point number: 5 v.value = z; 6 7 // Extract the real component: 8 float re = v.parts[ 0 ]; 9 10 return re; 11} 12 13// ... 14 15// Create a complex number: 16stdlib_complex64_t z = stdlib_complex64( 5.0f, 2.0f ); 17 18// ... 19 20// Access the real component: 21float re = realf( z ); 22// 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:
float
real component.float
imaginary component.Returns a single-precision complex floating-point number.
1stdlib_complex64_t z = stdlib_complex64( 5.0f, 2.0f );
The function accepts the following arguments:
[in] float
real component.[in] float
imaginary component.1stdlib_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.
1stdlib_complex64_t z = stdlib_complex64_from_float32( 5.0f );
The function accepts the following arguments:
[in] float
real component.1stdlib_complex64_t stdlib_complex64_from_float32( const float real );
Converts a double-precision floating-point number to a single-precision complex floating-point number.
1stdlib_complex64_t z = stdlib_complex64_from_float64( 5.0 );
The function accepts the following arguments:
[in] double
real component.1stdlib_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.
1stdlib_complex64_t z1 = stdlib_complex64( 5.0f, 3.0f ); 2stdlib_complex64_t z2 = stdlib_complex64_from_complex64( z1 );
The function accepts the following arguments:
[in] stdlib_complex64_t
single-precision complex floating-point number.1stdlib_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.
1stdlib_complex64_t z = stdlib_complex64_from_int8( 5 );
The function accepts the following arguments:
[in] int8_t
real component.1stdlib_complex64_t stdlib_complex64_from_int8( const int8_t real );
Converts an unsigned 8-bit integer to a single-precision complex floating-point number.
1stdlib_complex64_t z = stdlib_complex64_from_uint8( 5 );
The function accepts the following arguments:
[in] uint8_t
real component.1stdlib_complex64_t stdlib_complex64_from_uint8( const uint8_t real );
Converts a signed 16-bit integer to a single-precision complex floating-point number.
1stdlib_complex64_t z = stdlib_complex64_from_int16( 5 );
The function accepts the following arguments:
[in] int16_t
real component.1stdlib_complex64_t stdlib_complex64_from_int16( const int16_t real );
Converts an unsigned 16-bit integer to a single-precision complex floating-point number.
1stdlib_complex64_t z = stdlib_complex64_from_uint16( 5 );
The function accepts the following arguments:
[in] uint16_t
real component.1stdlib_complex64_t stdlib_complex64_from_uint16( const uint16_t real );
1#include "stdlib/complex/float32/ctor.h" 2#include <stdint.h> 3#include <stdio.h> 4 5/** 6* Return the real component of a single-precision complex floating-point number. 7* 8* @param z complex number 9* @return real component 10*/ 11static float real( const stdlib_complex64_t z ) { 12 stdlib_complex64_parts_t v; 13 14 // Assign a single-precision complex floating-point number: 15 v.value = z; 16 17 // Extract the real component: 18 float re = v.parts[ 0 ]; 19 20 return re; 21} 22 23/** 24* Return the imaginary component of a single-precision complex floating-point number. 25* 26* @param z complex number 27* @return imaginary component 28*/ 29static float imag( const stdlib_complex64_t z ) { 30 stdlib_complex64_parts_t v; 31 32 // Assign a single-precision complex floating-point number: 33 v.value = z; 34 35 // Extract the imaginary component: 36 float im = v.parts[ 1 ]; 37 38 return im; 39} 40 41int main( void ) { 42 const stdlib_complex64_t x[] = { 43 stdlib_complex64( 5.0f, 2.0f ), 44 stdlib_complex64( -2.0f, 1.0f ), 45 stdlib_complex64( 0.0f, -0.0f ), 46 stdlib_complex64( 0.0f/0.0f, 0.0f/0.0f ) 47 }; 48 49 stdlib_complex64_t v; 50 int i; 51 for ( i = 0; i < 4; i++ ) { 52 v = x[ i ]; 53 printf( "%f + %fi\n", real( v ), imag( v ) ); 54 } 55}
@stdlib/complex-cmplx
: create a complex number.@stdlib/complex-float64/ctor
: 128-bit complex number.This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
See LICENSE.
Copyright © 2016-2024. The Stdlib Authors.
No vulnerabilities found.
No security vulnerabilities found.