Skip to content

Commit

Permalink
feat: add complex/parse-float64
Browse files Browse the repository at this point in the history
PR-URL: #1362 
Closes: #1333 

Signed-off-by: Snehil Shah <snehilshah.989@gmail.com>
Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com>
Co-authored-by: Pranav <85227306+Pranavchiku@users.noreply.github.com>
Co-authored-by: Athan Reines <kgryte@gmail.com>
Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com> 
Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
  • Loading branch information
4 people authored Feb 28, 2024
1 parent 4e84566 commit 1154a11
Show file tree
Hide file tree
Showing 10 changed files with 728 additions and 0 deletions.
132 changes: 132 additions & 0 deletions lib/node_modules/@stdlib/complex/parse-float64/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<!--
@license Apache-2.0
Copyright (c) 2024 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.
-->

# parseComplex128

> Parse a string representation of a 128-bit [complex number][@stdlib/complex/float64].
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var parseComplex128 = require( '@stdlib/complex/parse-float64' );
```

#### parseComplex128( str )

Parse a string representation of a 128-bit [complex number][@stdlib/complex/float64].

```javascript
var real = require( '@stdlib/complex/real' );
var imag = require( '@stdlib/complex/imag' );

var str = '5 + 3i';

var z = parseComplex128( str );
// returns <Complex128>

var re = real( z );
// returns 5.0

var im = imag( z );
// returns 3.0
```

For details on the string format, see [Complex128][@stdlib/complex/float64].

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var parseComplex128 = require( '@stdlib/complex/parse-float64' );
var isComplex128 = require( '@stdlib/assert/is-complex128' );
var real = require( '@stdlib/complex/real' );
var imag = require( '@stdlib/complex/imag' );

var str = '1e3 - 2.75i';

var z = parseComplex128( str );
var bool = isComplex128( z );
// returns true

bool = ( real( z ) === 1e3 );
// returns true

bool = ( imag( z ) === -2.75 );
// returns true
```

</section>

<!-- /.examples -->

<!-- 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. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/complex/float64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/float64

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 isComplex128 = require( '@stdlib/assert/is-complex128' );
var pkg = require( './../package.json' ).name;
var parse = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var str;
var z;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
str = i + ' + ' + (i+1) + 'i';
z = parse( str );
if ( !(isComplex128(z)) ) {
b.fail( 'should return a Complex128' );
}
}
b.toc();
if ( !(isComplex128(z)) ) {
b.fail( 'should return a Complex128' );
}
b.pass( 'benchmark finished' );
b.end();
});
23 changes: 23 additions & 0 deletions lib/node_modules/@stdlib/complex/parse-float64/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

{{alias}}( str )
Parse a string representation of a 128-bit complex number.

Parameters
----------
str: string
String representation of a complex number.

Returns
-------
out: Complex128
128-bit complex number.

Examples
--------
> var str = '5 + 3i';
> var z = {{alias}}( str )
<Complex128>


See Also
--------
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2024 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

// MODULES //

/// <reference types="@stdlib/types"/>

import { Complex128 } from '@stdlib/types/complex';


/**
* Parse a string representation of a 128-bit complex number.
*
* @param str - string representation of a complex number
* @returns Complex128 instance
* @throws must provide a string recognized as a complex number
*
* @example
* var str = '5 + 3i';
*
* var z = parseComplex128( str );
* // returns <Complex128>
*/
declare function parseComplex128( str: string ): Complex128;


// EXPORTS //

export = parseComplex128;
44 changes: 44 additions & 0 deletions lib/node_modules/@stdlib/complex/parse-float64/docs/types/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2024 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 parseComplex128 = require( './index' );


// TESTS //

// The function returns a complex number...
{
parseComplex128( '5 + 3.5i' ); // $ExpectType Complex128
parseComplex128( '3' ); // $ExpectType Complex128
parseComplex128( '-8i' ); // $ExpectType Complex128
parseComplex128( '1e3 + 1e-3i' ); // $ExpectType Complex128
parseComplex128( 'NaN + NaNi' ); // $ExpectType Complex128
parseComplex128( 'Infinity - Infinityi' ); // $ExpectType Complex128
}

// The compiler throws an error if the function is provided a first argument that is not a string...
{
parseComplex128( true ); // $ExpectError
parseComplex128( false ); // $ExpectError
parseComplex128( null ); // $ExpectError
parseComplex128( undefined ); // $ExpectError
parseComplex128( 5 ); // $ExpectError
parseComplex128( [] ); // $ExpectError
parseComplex128( {} ); // $ExpectError
parseComplex128( ( x: number ): number => x ); // $ExpectError
}
42 changes: 42 additions & 0 deletions lib/node_modules/@stdlib/complex/parse-float64/examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 isComplex128 = require( '@stdlib/assert/is-complex128' );
var real = require( '@stdlib/complex/real' );
var imag = require( '@stdlib/complex/imag' );
var parseComplex128 = require( './../lib' );

var str = '-0.5 + 1.25i';

var z = parseComplex128( str );
console.log( z );
// => <Complex128>

var bool = ( isComplex128( z ) );
console.log( bool );
// => true

bool = ( real( z ) === -0.5 );
console.log( bool );
// => true

bool = ( imag( z ) === 1.25 );
console.log( bool );
// => true
42 changes: 42 additions & 0 deletions lib/node_modules/@stdlib/complex/parse-float64/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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';

/**
* Parse a string representation of a complex number and returns a Complex128 instance.
*
* @module @stdlib/complex/parse-float64
*
* @example
* var parseComplex128 = require( '@stdlib/complex/parse-float64' );
*
* var str = '1 + 2i';
*
* var z = parseComplex128( str );
* // returns <Complex128>
*/

// MODULES //

var main = require( './main.js' );


// EXPORTS //

module.exports = main;
Loading

1 comment on commit 1154a11

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
complex/parse-float64 $\color{green}132/132$
$\color{green}+100.00\%$
$\color{green}16/16$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}132/132$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.