parse

Parses a string representing a complex number into a complex like object {re: number, im: number}.

Usage

var parse = require( '@stdlib/complex/base/parse' );

parse( str )

Parses a string representing a complex number into a complex like object.

var parse = require( '@stdlib/complex/base/parse' );

var str = '5 + 3i';

var z = parse( str );
// returns <{re: 5, im: 3}>

Examples

var parse = require( '@stdlib/complex/base/parse' );

var str;
var z;

z = parse( '5 + 4i' );
// returns {'re' : 5, 'im' : 4}

z = parse( 'Infinity + 2.34i' );
// returns {'re' : Infinity, 'im' : 2.34}

z = parse( 'NaN + 4i' );
// returns {'re' : NaN, 'im' : 4}

z = parse( '45i55 + 5' );
// returns null

z = parse( '5 + 6 + 10e4i' );
// returns {'re' : 11, 'im' : 100000}

z = parse( {} );
// returns null
Did you find this page helpful?