-
-
Notifications
You must be signed in to change notification settings - Fork 837
feat: add complex/parse-float32 #1430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a7f6ec6
feat: add complex/parse-float32
kawaho2 5f0a185
Delete .gitignore
kawaho2 fcb501f
Revert "Delete .gitignore"
kawaho2 3b4b499
feat: add complex/parse-float32
kawaho2 6c1732e
feat: add complex/parse-float32
kawaho2 bb5ba55
remove extra line
Pranavchiku File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
lib/node_modules/@stdlib/complex/parse-float32/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<!-- | ||
|
||
@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. | ||
|
||
--> | ||
|
||
# parseComplex64 | ||
|
||
> Parse a string representation of a 64-bit [complex number][@stdlib/complex/float32]. | ||
|
||
<!-- 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 parseComplex64 = require( '@stdlib/complex/parse-float32' ); | ||
``` | ||
|
||
#### parseComplex64( str ) | ||
|
||
Parse a string representation of a 64-bit [complex number][@stdlib/complex/float32]. | ||
|
||
```javascript | ||
var parseComplex64 = require( '@stdlib/complex/parse-float32' ); | ||
var real = require( '@stdlib/complex/real' ); | ||
var imag = require( '@stdlib/complex/imag' ); | ||
|
||
var str = '5 + 3i'; | ||
|
||
var z = parseComplex64( str ); | ||
// returns <Complex64> | ||
|
||
var re = real( z ); | ||
// returns 5.0 | ||
|
||
var im = imag( z ); | ||
// returns 3.0 | ||
``` | ||
|
||
For details on the string format, see [Complex64][@stdlib/complex/float32]. | ||
|
||
</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 parseComplex64 = require( '@stdlib/complex/parse-float32' ); | ||
var isComplex64 = require( '@stdlib/assert/is-complex64' ); | ||
var real = require( '@stdlib/complex/real' ); | ||
var imag = require( '@stdlib/complex/imag' ); | ||
|
||
var str = '1e3 - 2.75i'; | ||
|
||
var z = parseComplex64( str ); | ||
var bool = isComplex64( 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/float32]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/complex/float32 | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
50 changes: 50 additions & 0 deletions
50
lib/node_modules/@stdlib/complex/parse-float32/benchmark/benchmark.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 isComplex64 = require( '@stdlib/assert/is-complex64' ); | ||
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 ( !(isComplex64(z)) ) { | ||
b.fail( 'should return a Complex64' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( !(isComplex64(z)) ) { | ||
b.fail( 'should return a Complex64' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
}); |
22 changes: 22 additions & 0 deletions
22
lib/node_modules/@stdlib/complex/parse-float32/docs/repl.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
{{alias}}( str ) | ||
Parse a string representation of a 64-bit complex number. | ||
|
||
Parameters | ||
---------- | ||
str: string | ||
String representation of a complex number. | ||
|
||
Returns | ||
------- | ||
out: Complex64 | ||
64-bit complex number. | ||
|
||
Examples | ||
-------- | ||
> var str = '5 + 3i'; | ||
> var z = {{alias}}( str ) | ||
<Complex64> | ||
|
||
See Also | ||
-------- |
46 changes: 46 additions & 0 deletions
46
lib/node_modules/@stdlib/complex/parse-float32/docs/types/index.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { Complex64 } from '@stdlib/types/complex'; | ||
|
||
|
||
/** | ||
* Parse a string representation of a 64-bit complex number. | ||
* | ||
* @param str - string representation of a complex number | ||
* @returns Complex64 instance | ||
* @throws must provide a string recognized as a complex number | ||
* | ||
* @example | ||
* var str = '5 + 3i'; | ||
* | ||
* var z = parseComplex64( str ); | ||
* // returns <Complex64> | ||
*/ | ||
declare function parseComplex64( str: string ): Complex64; | ||
|
||
|
||
// EXPORTS // | ||
|
||
export = parseComplex64; |
44 changes: 44 additions & 0 deletions
44
lib/node_modules/@stdlib/complex/parse-float32/docs/types/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 parseComplex64 = require( './index' ); | ||
|
||
|
||
// TESTS // | ||
|
||
// The function returns a complex number... | ||
{ | ||
parseComplex64( '5 + 3.5i' ); // $ExpectType Complex64 | ||
parseComplex64( '3' ); // $ExpectType Complex64 | ||
parseComplex64( '-8i' ); // $ExpectType Complex64 | ||
parseComplex64( '1e3 + 1e-3i' ); // $ExpectType Complex64 | ||
parseComplex64( 'NaN + NaNi' ); // $ExpectType Complex64 | ||
parseComplex64( 'Infinity - Infinityi' ); // $ExpectType Complex64 | ||
} | ||
|
||
// The compiler throws an error if the function is provided a first argument that is not a string... | ||
{ | ||
parseComplex64( true ); // $ExpectError | ||
parseComplex64( false ); // $ExpectError | ||
parseComplex64( null ); // $ExpectError | ||
parseComplex64( undefined ); // $ExpectError | ||
parseComplex64( 5 ); // $ExpectError | ||
parseComplex64( [] ); // $ExpectError | ||
parseComplex64( {} ); // $ExpectError | ||
parseComplex64( ( x: number ): number => x ); // $ExpectError | ||
} |
42 changes: 42 additions & 0 deletions
42
lib/node_modules/@stdlib/complex/parse-float32/examples/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 isComplex64 = require( '@stdlib/assert/is-complex64' ); | ||
var real = require( '@stdlib/complex/real' ); | ||
var imag = require( '@stdlib/complex/imag' ); | ||
var parseComplex64 = require( './../lib' ); | ||
|
||
var str = '-0.5 + 1.25i'; | ||
|
||
var z = parseComplex64( str ); | ||
console.log( z ); | ||
// => <Complex64> | ||
|
||
var bool = ( isComplex64( 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
42
lib/node_modules/@stdlib/complex/parse-float32/lib/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Complex64 instance. | ||
* | ||
* @module @stdlib/complex/parse-float32 | ||
* | ||
* @example | ||
* var parseComplex64 = require( '@stdlib/complex/parse-float32' ); | ||
* | ||
* var str = '1 + 2i'; | ||
* | ||
* var z = parseComplex64( str ); | ||
* // returns <Complex64> | ||
*/ | ||
|
||
// MODULES // | ||
|
||
var main = require( './main.js' ); | ||
|
||
|
||
// EXPORTS // | ||
|
||
module.exports = main; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.