repl.txt (2073B)
1 2 {{alias}}( x, y[, scale] ) 3 Computes the relative difference of two real numbers in units of double- 4 precision floating-point epsilon. 5 6 By default, the function scales the absolute difference by dividing the 7 absolute difference by the maximum absolute value of `x` and `y`. To scale 8 by a different function, specify a scale function name. 9 10 The following `scale` functions are supported: 11 12 - 'max-abs': maximum absolute value of `x` and `y` (default). 13 - 'max': maximum value of `x` and `y`. 14 - 'min-abs': minimum absolute value of `x` and `y`. 15 - 'min': minimum value of `x` and `y`. 16 - 'mean-abs': arithmetic mean of the absolute values of `x` and `y`. 17 - 'mean': arithmetic mean of `x` and `y`. 18 - 'x': `x` (*noncommutative*). 19 - 'y': `y` (*noncommutative*). 20 21 To use a custom scale function, provide a function which accepts two numeric 22 arguments `x` and `y`. 23 24 If computing the relative difference in units of epsilon will result in 25 overflow, the function returns the maximum double-precision floating-point 26 number. 27 28 If the absolute difference of `x` and `y` is `0`, the relative difference is 29 always `0`. 30 31 If `|x| = |y| = infinity`, the function returns `NaN`. 32 33 If `|x| = |-y| = infinity`, the relative difference is `+infinity`. 34 35 If a `scale` function returns `0`, the function returns `NaN`. 36 37 Parameters 38 ---------- 39 x: number 40 First number. 41 42 y: number 43 Second number. 44 45 scale: string|Function (optional) 46 Scale function. Default: `'max-abs'`. 47 48 Returns 49 ------- 50 out: number 51 Relative difference in units of double-precision floating-point epsilon. 52 53 Examples 54 -------- 55 > var d = {{alias}}( 12.15, 12.149999999999999 ) 56 ~0.658 57 > d = {{alias}}( 2.4341309458983933, 2.4341309458633909, 'mean-abs' ) 58 ~64761.512 59 60 // Custom scale function: 61 > function scale( x, y ) { return ( x > y ) ? y : x; }; 62 > d = {{alias}}( 1.0000000000000002, 1.0000000000000100, scale ) 63 ~44 64 65 See Also 66 -------- 67