Skip to content
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

docs(math/base/ops): improve math/base/ops README.md examples #1722

Merged
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 );

Planeshifter marked this conversation as resolved.
Show resolved Hide resolved
console.log( ns.cmul( z1, z2 ) );
// => Complex128 { re: -13.0, im: -1.0 }
Planeshifter marked this conversation as resolved.
Show resolved Hide resolved

// Operations for signed 32-bit integers:
// 2^30 * -5 = -5368709120 => 32-bit integer overflow
console.log( ns.imul( 1073741824|0, -5|0 ) ); // => -1073741824
Planeshifter marked this conversation as resolved.
Show resolved Hide resolved

// 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
34 changes: 32 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,37 @@

'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
Planeshifter marked this conversation as resolved.
Show resolved Hide resolved

// Operations for complex numbers
Planeshifter marked this conversation as resolved.
Show resolved Hide resolved
var z1 = new Complex128( 5.0, 3.0 );
var z2 = new Complex128( -2.0, 1.0 );

console.log( ns.cmul( z1, z2 ) ); // => Complex128 { re: -13.0, im: -1.0 }
Planeshifter marked this conversation as resolved.
Show resolved Hide resolved

// 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 ]
Loading