-
-
Notifications
You must be signed in to change notification settings - Fork 836
feat: add complex/parse-float64
#1362
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 6 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8b8797c
Add `@stdlib/complex/parse-float64`
Snehil-Shah 9d25909
fix: failing tests
Snehil-Shah 5ee83f7
fix: benchmarks
Snehil-Shah fc7bd0a
fix: lint errors and suggested changes
Snehil-Shah 1c4e03d
fix: workflow lint errors
Snehil-Shah a4fe19f
test: add more varied test cases & examples
Snehil-Shah 72d223a
fix: suggested changes and add more test cases
Snehil-Shah 1ee982f
fix lint errors
Snehil-Shah a932f62
Update lib/node_modules/@stdlib/complex/parse-float64/docs/repl.txt
Snehil-Shah 26956a4
fix: lint suggestions
Snehil-Shah 9fe2a41
feat: extend to include exp notation, NaN & Infinity
Snehil-Shah 744d46b
Update lib/node_modules/@stdlib/complex/parse-float64/docs/types/test.ts
Snehil-Shah 9a40758
Update lib/node_modules/@stdlib/complex/parse-float64/docs/repl.txt
Snehil-Shah c92f7d7
fix: suggestions
Snehil-Shah cf467ca
fix: ts tests
Snehil-Shah 879f1a5
fix: conventional error messages
Snehil-Shah 37e3f55
refactor: use assertion package and format for error messages
Planeshifter 074005e
Update lib/node_modules/@stdlib/complex/parse-float64/examples/index.js
Planeshifter 429dd82
Update lib/node_modules/@stdlib/complex/parse-float64/docs/types/inde…
Planeshifter 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
130 changes: 130 additions & 0 deletions
130
lib/node_modules/@stdlib/complex/parse-float64/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,130 @@ | ||
<!-- | ||
|
||
@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 ) | ||
|
||
Parses 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 + 3j'; | ||
|
||
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 Complex128 = require( '@stdlib/complex/float64' ); | ||
var parseComplex128 = require( '@stdlib/complex/parse-float64' ); | ||
|
||
var str = '8 - 2.75j'; | ||
|
||
var z = parseComplex128( str ); | ||
var bool = ( z instanceof Complex128 ); | ||
// returns true | ||
|
||
bool = ( z.re === 8.0 ); | ||
// returns true | ||
|
||
bool = ( z.im === -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 --> |
50 changes: 50 additions & 0 deletions
50
lib/node_modules/@stdlib/complex/parse-float64/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 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) + 'j'; | ||
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(); | ||
}); |
27 changes: 27 additions & 0 deletions
27
lib/node_modules/@stdlib/complex/parse-float64/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,27 @@ | ||
|
||
{{alias}}( str ) | ||
Parses a string representation of a 128-bit complex number. | ||
|
||
Parameters | ||
---------- | ||
str: string | ||
String representation of a complex number. | ||
|
||
Returns | ||
------- | ||
out: Complex128 | ||
If the string is recognized as a complex number, a | ||
Complex128 instance is returned. | ||
Snehil-Shah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Examples | ||
-------- | ||
> var str = '5 + 3j'; | ||
> var z = {{alias}}( str ) | ||
<Complex128> | ||
|
||
References | ||
---------- | ||
(Add any references here) | ||
Snehil-Shah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
See Also | ||
-------- |
44 changes: 44 additions & 0 deletions
44
lib/node_modules/@stdlib/complex/parse-float64/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,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. | ||
*/ | ||
|
||
// TypeScript Version: 4.1 | ||
|
||
interface Complex128 { | ||
Snehil-Shah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
re: number; | ||
im: number; | ||
} | ||
|
||
/** | ||
* Parse a string representation of a 128-bit complex number. | ||
* | ||
* @param str - string representation of a complex number | ||
* @returns Complex128 instance | ||
* @throws Will throw an error if the string is not recognized as a complex number | ||
Planeshifter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @example | ||
* var str = '5 + 3j'; | ||
* | ||
* var z = parseComplex128( str ); | ||
* // returns <Complex128> | ||
*/ | ||
declare function parseComplex128( str: string ): Complex128; | ||
|
||
|
||
// EXPORTS // | ||
|
||
export = parseComplex128; |
58 changes: 58 additions & 0 deletions
58
lib/node_modules/@stdlib/complex/parse-float64/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,58 @@ | ||
/* | ||
* @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 parses a string representation of a complex number... | ||
Snehil-Shah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
const str = '5 + 3j'; | ||
parseComplex128( str ); // $ExpectType Complex128 | ||
} | ||
|
||
// The function parses a string representation of a complex number (only real part)... | ||
{ | ||
const str = '3'; | ||
parseComplex128( str ); // $ExpectType Complex128 | ||
} | ||
|
||
// The function parses a string representation of a complex number (only imaginary part)... | ||
{ | ||
const str = '8j'; | ||
parseComplex128( str ); // $ExpectType Complex128 | ||
} | ||
|
||
// The function throws an error if the input is not recognized as a complex number... | ||
{ | ||
const str = 'beep boop'; | ||
parseComplex128( str ); // $ExpectError | ||
} | ||
|
||
// 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 | ||
} |
40 changes: 40 additions & 0 deletions
40
lib/node_modules/@stdlib/complex/parse-float64/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,40 @@ | ||
/** | ||
* @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 Complex128 = require( '@stdlib/complex/float64' ); | ||
var parseComplex128 = require( './../lib' ); | ||
|
||
var str = '-0.5 + 1.25j'; | ||
|
||
var z = parseComplex128( str ); | ||
console.log( z ); | ||
// => <Complex128> | ||
|
||
var bool = ( z instanceof Complex128 ); | ||
console.log( bool ); | ||
// => true | ||
Snehil-Shah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
bool = ( z.re === -0.5 ); | ||
console.log( bool ); | ||
// => true | ||
|
||
bool = ( z.im === 1.25 ); | ||
console.log( bool ); | ||
// => true |
42 changes: 42 additions & 0 deletions
42
lib/node_modules/@stdlib/complex/parse-float64/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'; | ||
|
||
/** | ||
* Parses a string representation of a complex number and returns a Complex128 instance. | ||
Snehil-Shah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @module @stdlib/complex/parse-float64 | ||
* | ||
* @example | ||
* var parseComplex128 = require( '@stdlib/complex/parse-float64' ); | ||
* | ||
* var str = '1 + 2j'; | ||
* | ||
* var z = parseComplex128( str ); | ||
* // returns <Complex128> | ||
*/ | ||
|
||
// 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.