Skip to content

Commit

Permalink
docs: improve math/base/ops README.md examples
Browse files Browse the repository at this point in the history
PR-URL: #1722
Closes: #1569 

---------

Signed-off-by: Philipp Burckhardt <[email protected]>
Co-authored-by: Philipp Burckhardt <[email protected]>
Reviewed-by: Philipp Burckhardt <[email protected]>
  • Loading branch information
EuniceSim142 and Planeshifter authored Mar 7, 2024
1 parent 8b0d39d commit ad45e04
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
37 changes: 35 additions & 2 deletions lib/node_modules/@stdlib/math/base/ops/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,43 @@ The namespace contains the following functions:
<!-- eslint no-undef: "error" -->

```javascript
var objectKeys = require( '@stdlib/utils/keys' );
var Complex128 = require( '@stdlib/complex/float64' );
var ns = require( '@stdlib/math/base/ops' );

console.log( objectKeys( ns ) );
// Operations for double-precision floating point numbers:
console.log( ns.add( 1.25, 0.45 ) );
// => 1.7

console.log( ns.sub( 1.25, 0.45 ) );
// => 0.8

// Operations for single-precision floating point numbers:
console.log( ns.mulf( 1.3, 1.2 ) );
// => ~1.56

console.log( ns.divf( 1.2, 0.4 ) );
// => 3.0

// Operations for complex numbers:
var z1 = new Complex128( 5.0, 3.0 );
var z2 = new Complex128( -2.0, 1.0 );
console.log( ns.cmul( z1, z2 ) ); // { 're': -13.0, 'im': -1.0 }
// => <Complex128>

// Operations for signed 32-bit integers:
// 2^30 * -5 = -5368709120 => 32-bit integer overflow
console.log( ns.imul( 1073741824|0, -5|0 ) );
// => -1073741824

// Operations for unsigned 32-bit integers:
// 2^31 * 5 = 10737418240 => 32-bit integer overflow
console.log( ns.umul( 2147483648>>>0, 5>>>0 ) );
// => 2147483648

// Operations for double word product:
// -(2^31) * 2^30 = -2305843009213694000 => 32-bit integer overflow
console.log( ns.imuldw( 0x80000000|0, 0x40000000|0 ) );
// => [ -536870912, 0 ]
```

</section>
Expand Down
37 changes: 35 additions & 2 deletions lib/node_modules/@stdlib/math/base/ops/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,40 @@

'use strict';

var objectKeys = require( '@stdlib/utils/keys' );
var Complex128 = require( '@stdlib/complex/float64' );
var ns = require( './../lib' );

console.log( objectKeys( ns ) );
// Operations for double-precision floating point numbers:
console.log( ns.add( 1.25, 0.45 ) );
// => 1.7

console.log( ns.sub( 1.25, 0.45 ) );
// => 0.8

// Operations for single-precision floating point numbers:
console.log( ns.mulf( 1.3, 1.2 ) );
// => ~1.56

console.log( ns.divf( 1.2, 0.4 ) );
// => 3.0

// Operations for complex numbers:
var z1 = new Complex128( 5.0, 3.0 );
var z2 = new Complex128( -2.0, 1.0 );
console.log( ns.cmul( z1, z2 ) ); // {'re': -13.0, 'im': -1.0 }
// => <Complex128>

// Operations for signed 32-bit integers:
// 2^30 * -5 = -5368709120 => 32-bit integer overflow
console.log( ns.imul( 1073741824|0, -5|0 ) );
// => -1073741824

// Operations for unsigned 32-bit integers:
// 2^31 * 5 = 10737418240 => 32-bit integer overflow
console.log( ns.umul( 2147483648>>>0, 5>>>0 ) );
// => 2147483648

// Operations for couble word product:
// -(2^31) * 2^30 = -2305843009213694000 => 32-bit integer overflow
console.log( ns.imuldw( 0x80000000|0, 0x40000000|0 ) );
// => [ -536870912, 0 ]

1 comment on commit ad45e04

@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
math/base/ops $\color{green}258/258$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}0/0$
$\color{green}+100.00\%$
$\color{green}258/258$
$\color{green}+100.00\%$

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

Please sign in to comment.