Skip to content

Commit ad45e04

Browse files
docs: improve math/base/ops README.md examples
PR-URL: #1722 Closes: #1569 --------- Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com> Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com> Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent 8b0d39d commit ad45e04

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed

lib/node_modules/@stdlib/math/base/ops/README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,43 @@ The namespace contains the following functions:
8787
<!-- eslint no-undef: "error" -->
8888

8989
```javascript
90-
var objectKeys = require( '@stdlib/utils/keys' );
90+
var Complex128 = require( '@stdlib/complex/float64' );
9191
var ns = require( '@stdlib/math/base/ops' );
9292

93-
console.log( objectKeys( ns ) );
93+
// Operations for double-precision floating point numbers:
94+
console.log( ns.add( 1.25, 0.45 ) );
95+
// => 1.7
96+
97+
console.log( ns.sub( 1.25, 0.45 ) );
98+
// => 0.8
99+
100+
// Operations for single-precision floating point numbers:
101+
console.log( ns.mulf( 1.3, 1.2 ) );
102+
// => ~1.56
103+
104+
console.log( ns.divf( 1.2, 0.4 ) );
105+
// => 3.0
106+
107+
// Operations for complex numbers:
108+
var z1 = new Complex128( 5.0, 3.0 );
109+
var z2 = new Complex128( -2.0, 1.0 );
110+
console.log( ns.cmul( z1, z2 ) ); // { 're': -13.0, 'im': -1.0 }
111+
// => <Complex128>
112+
113+
// Operations for signed 32-bit integers:
114+
// 2^30 * -5 = -5368709120 => 32-bit integer overflow
115+
console.log( ns.imul( 1073741824|0, -5|0 ) );
116+
// => -1073741824
117+
118+
// Operations for unsigned 32-bit integers:
119+
// 2^31 * 5 = 10737418240 => 32-bit integer overflow
120+
console.log( ns.umul( 2147483648>>>0, 5>>>0 ) );
121+
// => 2147483648
122+
123+
// Operations for double word product:
124+
// -(2^31) * 2^30 = -2305843009213694000 => 32-bit integer overflow
125+
console.log( ns.imuldw( 0x80000000|0, 0x40000000|0 ) );
126+
// => [ -536870912, 0 ]
94127
```
95128

96129
</section>

lib/node_modules/@stdlib/math/base/ops/examples/index.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,40 @@
1818

1919
'use strict';
2020

21-
var objectKeys = require( '@stdlib/utils/keys' );
21+
var Complex128 = require( '@stdlib/complex/float64' );
2222
var ns = require( './../lib' );
2323

24-
console.log( objectKeys( ns ) );
24+
// Operations for double-precision floating point numbers:
25+
console.log( ns.add( 1.25, 0.45 ) );
26+
// => 1.7
27+
28+
console.log( ns.sub( 1.25, 0.45 ) );
29+
// => 0.8
30+
31+
// Operations for single-precision floating point numbers:
32+
console.log( ns.mulf( 1.3, 1.2 ) );
33+
// => ~1.56
34+
35+
console.log( ns.divf( 1.2, 0.4 ) );
36+
// => 3.0
37+
38+
// Operations for complex numbers:
39+
var z1 = new Complex128( 5.0, 3.0 );
40+
var z2 = new Complex128( -2.0, 1.0 );
41+
console.log( ns.cmul( z1, z2 ) ); // {'re': -13.0, 'im': -1.0 }
42+
// => <Complex128>
43+
44+
// Operations for signed 32-bit integers:
45+
// 2^30 * -5 = -5368709120 => 32-bit integer overflow
46+
console.log( ns.imul( 1073741824|0, -5|0 ) );
47+
// => -1073741824
48+
49+
// Operations for unsigned 32-bit integers:
50+
// 2^31 * 5 = 10737418240 => 32-bit integer overflow
51+
console.log( ns.umul( 2147483648>>>0, 5>>>0 ) );
52+
// => 2147483648
53+
54+
// Operations for couble word product:
55+
// -(2^31) * 2^30 = -2305843009213694000 => 32-bit integer overflow
56+
console.log( ns.imuldw( 0x80000000|0, 0x40000000|0 ) );
57+
// => [ -536870912, 0 ]

0 commit comments

Comments
 (0)