|
20 | 20 |
|
21 | 21 | /* eslint-disable max-lines */ |
22 | 22 |
|
| 23 | +import add = require( '@stdlib/number/float64/base/add' ); |
| 24 | +import add3 = require( '@stdlib/number/float64/base/add3' ); |
| 25 | +import add4 = require( '@stdlib/number/float64/base/add4' ); |
| 26 | +import add5 = require( '@stdlib/number/float64/base/add5' ); |
23 | 27 | import assert = require( '@stdlib/number/float64/base/assert' ); |
| 28 | +import div = require( '@stdlib/number/float64/base/div' ); |
24 | 29 | import exponent = require( '@stdlib/number/float64/base/exponent' ); |
25 | 30 | import fromBinaryString = require( '@stdlib/number/float64/base/from-binary-string' ); |
26 | 31 | import fromInt64Bytes = require( '@stdlib/number/float64/base/from-int64-bytes' ); |
27 | 32 | import fromWords = require( '@stdlib/number/float64/base/from-words' ); |
28 | 33 | import getHighWord = require( '@stdlib/number/float64/base/get-high-word' ); |
29 | 34 | import getLowWord = require( '@stdlib/number/float64/base/get-low-word' ); |
| 35 | +import identity = require( '@stdlib/number/float64/base/identity' ); |
| 36 | +import mul = require( '@stdlib/number/float64/base/mul' ); |
30 | 37 | import normalize = require( '@stdlib/number/float64/base/normalize' ); |
31 | 38 | import setHighWord = require( '@stdlib/number/float64/base/set-high-word' ); |
32 | 39 | import setLowWord = require( '@stdlib/number/float64/base/set-low-word' ); |
33 | 40 | import signbit = require( '@stdlib/number/float64/base/signbit' ); |
| 41 | +import sub = require( '@stdlib/number/float64/base/sub' ); |
34 | 42 | import toBinaryString = require( '@stdlib/number/float64/base/to-binary-string' ); |
35 | 43 | import float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); |
36 | 44 | import float64ToInt32 = require( '@stdlib/number/float64/base/to-int32' ); |
37 | 45 | import float64ToInt64Bytes = require( '@stdlib/number/float64/base/to-int64-bytes' ); |
38 | 46 | import float64ToUint32 = require( '@stdlib/number/float64/base/to-uint32' ); |
39 | 47 | import toWords = require( '@stdlib/number/float64/base/to-words' ); |
| 48 | +import ulpdiff = require( '@stdlib/number/float64/base/ulp-difference' ); |
40 | 49 |
|
41 | 50 | /** |
42 | 51 | * Interface describing the `base` namespace. |
43 | 52 | */ |
44 | 53 | interface Namespace { |
| 54 | + /** |
| 55 | + * Computes the sum of two double-precision floating-point numbers `x` and `y`. |
| 56 | + * |
| 57 | + * @param x - first input value |
| 58 | + * @param y - second input value |
| 59 | + * @returns sum |
| 60 | + * |
| 61 | + * @example |
| 62 | + * var v = ns.add( -1.0, 5.0 ); |
| 63 | + * // returns 4.0 |
| 64 | + * |
| 65 | + * @example |
| 66 | + * var v = ns.add( 2.0, 5.0 ); |
| 67 | + * // returns 7.0 |
| 68 | + * |
| 69 | + * @example |
| 70 | + * var v = ns.add( 0.0, 5.0 ); |
| 71 | + * // returns 5.0 |
| 72 | + * |
| 73 | + * @example |
| 74 | + * var v = ns.add( -0.0, 0.0 ); |
| 75 | + * // returns 0.0 |
| 76 | + * |
| 77 | + * @example |
| 78 | + * var v = ns.add( NaN, NaN ); |
| 79 | + * // returns NaN |
| 80 | + */ |
| 81 | + add: typeof add; |
| 82 | + |
| 83 | + /** |
| 84 | + * Computes the sum of three double-precision floating-point numbers. |
| 85 | + * |
| 86 | + * @param x - first input value |
| 87 | + * @param y - second input value |
| 88 | + * @param z - third input value |
| 89 | + * @returns sum |
| 90 | + * |
| 91 | + * @example |
| 92 | + * var v = ns.add3( -1.0, 5.0, 2.0 ); |
| 93 | + * // returns 6.0 |
| 94 | + * |
| 95 | + * @example |
| 96 | + * var v = ns.add3( 2.0, 5.0, 2.0 ); |
| 97 | + * // returns 9.0 |
| 98 | + * |
| 99 | + * @example |
| 100 | + * var v = ns.add3( 0.0, 5.0, 2.0 ); |
| 101 | + * // returns 7.0 |
| 102 | + * |
| 103 | + * @example |
| 104 | + * var v = ns.add3( -0.0, 0.0, -0.0 ); |
| 105 | + * // returns 0.0 |
| 106 | + * |
| 107 | + * @example |
| 108 | + * var v = ns.add3( NaN, NaN, NaN ); |
| 109 | + * // returns NaN |
| 110 | + */ |
| 111 | + add3: typeof add3; |
| 112 | + |
| 113 | + /** |
| 114 | + * Computes the sum of four double-precision floating-point numbers. |
| 115 | + * |
| 116 | + * @param x - first input value |
| 117 | + * @param y - second input value |
| 118 | + * @param z - third input value |
| 119 | + * @param w - fourth input value |
| 120 | + * @returns sum |
| 121 | + * |
| 122 | + * @example |
| 123 | + * var v = ns.add4( -1.0, 5.0, 2.0, -3.0 ); |
| 124 | + * // returns 3.0 |
| 125 | + * |
| 126 | + * @example |
| 127 | + * var v = ns.add4( 2.0, 5.0, 2.0, -3.0 ); |
| 128 | + * // returns 6.0 |
| 129 | + * |
| 130 | + * @example |
| 131 | + * var v = ns.add4( 0.0, 5.0, 2.0, -3.0 ); |
| 132 | + * // returns 4.0 |
| 133 | + * |
| 134 | + * @example |
| 135 | + * var v = ns.add4( -0.0, 0.0, -0.0, -0.0 ); |
| 136 | + * // returns 0.0 |
| 137 | + * |
| 138 | + * @example |
| 139 | + * var v = ns.add4( NaN, NaN, NaN, NaN ); |
| 140 | + * // returns NaN |
| 141 | + */ |
| 142 | + add4: typeof add4; |
| 143 | + |
| 144 | + /** |
| 145 | + * Computes the sum of five double-precision floating-point numbers. |
| 146 | + * |
| 147 | + * @param x - first input value |
| 148 | + * @param y - second input value |
| 149 | + * @param z - third input value |
| 150 | + * @param w - fourth input value |
| 151 | + * @param u - fifth input value |
| 152 | + * @returns sum |
| 153 | + * |
| 154 | + * @example |
| 155 | + * var v = ns.add5( -1.0, 5.0, 2.0, -3.0, 4.0 ); |
| 156 | + * // returns 7.0 |
| 157 | + * |
| 158 | + * @example |
| 159 | + * var v = ns.add5( 2.0, 5.0, 2.0, -3.0, 4.0 ); |
| 160 | + * // returns 10.0 |
| 161 | + * |
| 162 | + * @example |
| 163 | + * var v = ns.add5( 0.0, 5.0, 2.0, -3.0, 4.0 ); |
| 164 | + * // returns 8.0 |
| 165 | + * |
| 166 | + * @example |
| 167 | + * var v = ns.add5( -0.0, 0.0, -0.0, -0.0, -0.0 ); |
| 168 | + * // returns 0.0 |
| 169 | + * |
| 170 | + * @example |
| 171 | + * var v = ns.add5( NaN, NaN, NaN, NaN, NaN ); |
| 172 | + * // returns NaN |
| 173 | + */ |
| 174 | + add5: typeof add5; |
| 175 | + |
45 | 176 | /** |
46 | 177 | * Base double-precision floating-point number assert functions. |
47 | 178 | */ |
48 | 179 | assert: typeof assert; |
49 | 180 |
|
| 181 | + /** |
| 182 | + * Divides two double-precision floating-point numbers `x` and `y`. |
| 183 | + * |
| 184 | + * @param x - first input value (divided) |
| 185 | + * @param y - second input value (divisor) |
| 186 | + * @returns result |
| 187 | + * |
| 188 | + * @example |
| 189 | + * var v = ns.div( -1.0, 5.0 ); |
| 190 | + * // returns -0.2 |
| 191 | + * |
| 192 | + * @example |
| 193 | + * var v = ns.div( 2.0, 5.0 ); |
| 194 | + * // returns 0.4 |
| 195 | + * |
| 196 | + * @example |
| 197 | + * var v = ns.div( 0.0, 5.0 ); |
| 198 | + * // returns 0.0 |
| 199 | + * |
| 200 | + * @example |
| 201 | + * var v = ns.div( -0.0, 5.0 ); |
| 202 | + * // returns -0.0 |
| 203 | + * |
| 204 | + * @example |
| 205 | + * var v = ns.div( NaN, NaN ); |
| 206 | + * // returns NaN |
| 207 | + */ |
| 208 | + div: typeof div; |
| 209 | + |
50 | 210 | /** |
51 | 211 | * Returns an integer corresponding to the unbiased exponent of a double-precision floating-point number. |
52 | 212 | * |
@@ -251,6 +411,63 @@ interface Namespace { |
251 | 411 | */ |
252 | 412 | getLowWord: typeof getLowWord; |
253 | 413 |
|
| 414 | + /** |
| 415 | + * Evaluates the identity function for double-precision floating-point number `x`. |
| 416 | + * |
| 417 | + * @param x - input value |
| 418 | + * @returns input value |
| 419 | + * |
| 420 | + * @example |
| 421 | + * var v = ns.identity( -1.0 ); |
| 422 | + * // returns -1.0 |
| 423 | + * |
| 424 | + * @example |
| 425 | + * var v = ns.identity( 2.0 ); |
| 426 | + * // returns 2.0 |
| 427 | + * |
| 428 | + * @example |
| 429 | + * var v = ns.identity( 0.0 ); |
| 430 | + * // returns 0.0 |
| 431 | + * |
| 432 | + * @example |
| 433 | + * var v = ns.identity( -0.0 ); |
| 434 | + * // returns -0.0 |
| 435 | + * |
| 436 | + * @example |
| 437 | + * var v = ns.identity( NaN ); |
| 438 | + * // returns NaN |
| 439 | + */ |
| 440 | + identity: typeof identity; |
| 441 | + |
| 442 | + /** |
| 443 | + * Multiplies two double-precision floating-point numbers `x` and `y`. |
| 444 | + * |
| 445 | + * @param x - first input value |
| 446 | + * @param y - second input value |
| 447 | + * @returns result |
| 448 | + * |
| 449 | + * @example |
| 450 | + * var v = ns.mul( -1.0, 5.0 ); |
| 451 | + * // returns -5.0 |
| 452 | + * |
| 453 | + * @example |
| 454 | + * var v = ns.mul( 2.0, 5.0 ); |
| 455 | + * // returns 10.0 |
| 456 | + * |
| 457 | + * @example |
| 458 | + * var v = ns.mul( 0.0, 5.0 ); |
| 459 | + * // returns 0.0 |
| 460 | + * |
| 461 | + * @example |
| 462 | + * var v = ns.mul( -0.0, 0.0 ); |
| 463 | + * // returns -0.0 |
| 464 | + * |
| 465 | + * @example |
| 466 | + * var v = ns.mul( NaN, NaN ); |
| 467 | + * // returns NaN |
| 468 | + */ |
| 469 | + mul: typeof mul; |
| 470 | + |
254 | 471 | /** |
255 | 472 | * Returns a normal number `y` and exponent `exp` satisfying \\(x = y \cdot 2^\mathrm{exp}\\). |
256 | 473 | * |
@@ -431,6 +648,35 @@ interface Namespace { |
431 | 648 | */ |
432 | 649 | signbit: typeof signbit; |
433 | 650 |
|
| 651 | + /** |
| 652 | + * Subtracts two double-precision floating-point numbers `x` and `y`. |
| 653 | + * |
| 654 | + * @param x - first input value |
| 655 | + * @param y - second input value |
| 656 | + * @returns result |
| 657 | + * |
| 658 | + * @example |
| 659 | + * var v = ns.sub( -1.0, 5.0 ); |
| 660 | + * // returns -6.0 |
| 661 | + * |
| 662 | + * @example |
| 663 | + * var v = ns.sub( 2.0, 5.0 ); |
| 664 | + * // returns -3.0 |
| 665 | + * |
| 666 | + * @example |
| 667 | + * var v = ns.sub( 0.0, 5.0 ); |
| 668 | + * // returns -5.0 |
| 669 | + * |
| 670 | + * @example |
| 671 | + * var v = ns.sub( -0.0, 0.0 ); |
| 672 | + * // returns -0.0 |
| 673 | + * |
| 674 | + * @example |
| 675 | + * var v = ns.sub( NaN, NaN ); |
| 676 | + * // returns NaN |
| 677 | + */ |
| 678 | + sub: typeof sub; |
| 679 | + |
434 | 680 | /** |
435 | 681 | * Returns a string giving the literal bit representation of a double-precision floating-point number. |
436 | 682 | * |
@@ -589,6 +835,41 @@ interface Namespace { |
589 | 835 | * // returns [ 1774486211, 2479577218 ] |
590 | 836 | */ |
591 | 837 | toWords: typeof toWords; |
| 838 | + |
| 839 | + /** |
| 840 | + * Computes the number of representable double-precision floating-point values that separate two double-precision floating-point numbers along the real number line. |
| 841 | + * |
| 842 | + * ## Notes |
| 843 | + * |
| 844 | + * - Adjacent double-precision floating-point numbers differ by 1 ulp (unit in the last place). |
| 845 | + * - Signed zeros differ only in the sign bit but are considered numerically equal, and thus their ULP difference is 0. |
| 846 | + * |
| 847 | + * @param x - first input value |
| 848 | + * @param y - second input value |
| 849 | + * @returns result |
| 850 | + * |
| 851 | + * @example |
| 852 | + * var EPS = require( '@stdlib/constants/float64/eps' ); |
| 853 | + * |
| 854 | + * var d = ns.ulpdiff( 1.0, 1.0+EPS ); |
| 855 | + * // returns 1.0 |
| 856 | + * |
| 857 | + * d = ns.ulpdiff( 1.0+EPS, 1.0 ); |
| 858 | + * // returns 1.0 |
| 859 | + * |
| 860 | + * d = ns.ulpdiff( 1.0, 1.0+EPS+EPS ); |
| 861 | + * // returns 2.0 |
| 862 | + * |
| 863 | + * d = ns.ulpdiff( 1.0, NaN ); |
| 864 | + * // returns NaN |
| 865 | + * |
| 866 | + * d = ns.ulpdiff( NaN, 1.0 ); |
| 867 | + * // returns NaN |
| 868 | + * |
| 869 | + * d = ns.ulpdiff( NaN, NaN ); |
| 870 | + * // returns NaN |
| 871 | + */ |
| 872 | + ulpdiff: typeof ulpdiff; |
592 | 873 | } |
593 | 874 |
|
594 | 875 | /** |
|
0 commit comments