1 ! Copyright (C) 2011 John Benediktsson
2 ! See https://factorcode.org/license.txt for BSD license
4 USING: kernel literals math math.functions ranges picomath
11 { -3 -0.999977909503 }
12 { -1 -0.842700792950 }
14 { 0.5 0.520499877813 }
15 { 2.1 0.997020533344 }
16 } [ [ first erf ] [ second - ] bi abs ] map
22 { -1 -0.632120558828558 }
24 { $[ 1e-5 1e-8 - ] 0.000009990049900216168 }
25 { $[ 1e-5 1e-8 + ] 0.00001001005010021717 }
26 { 0.5 0.6487212707001282 }
27 } [ [ first expm1 ] [ second - ] bi abs ] map
33 { -3 0.00134989803163 }
36 { 0.5 0.691462461274 }
37 { 2.1 0.982135579437 }
38 } [ [ first phi ] [ second - ] bi abs ] map
42 : factorial ( n -- n! ) [ 1 ] [ [1..b] 1 [ * ] reduce ] if-zero ;
45 { 0 1 10 100 1000 10000 } [
46 [ factorial log ] [ log-factorial ] bi - abs
50 : relative-error ( approx value -- relative-error )
56 { 2.19824158876e-16 4.5490905327e+15 } ! 0.99*DBL_EPSILON
57 { 2.24265050974e-16 4.45900953205e+15 } ! 1.01*DBL_EPSILON
58 { 0.00099 1009.52477271 }
59 { 0.00100 999.423772485 }
60 { 0.00101 989.522792258 }
62 { 11.999 39819417.4793 }
64 { 12.001 40014424.1571 }
65 { 15.2 149037380723.0 }
66 } [ [ first gamma ] [ second relative-error ] bi ] map
72 { 1e-12 27.6310211159 }
73 { 0.9999 5.77297915613e-05 }
74 { 1.0001 -5.77133422205e-05 }
75 { 3.1 0.787375083274 }
77 { 11.9999 17.5020635801 }
79 { 12.0001 17.5025521125 }
80 { 27.4 62.5755868211 }
81 } [ [ first log-gamma ] [ second relative-error ] bi ] map