Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tests/x86efi/float/fexplog.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / x86efi / float / fexplog.om` 89 lines ยท 2359 bytes Raw Blame History 1 2 note e^x for every f64 x. Cody-Waite reduction x = k ln2 + r with |r| <= ln2/2, then the Taylor 3 note polynomial of degree 13 in Horner form, then scaling by 2^k1 * 2^k2 (k1 = k/2) so every 4 note intermediate is normal and a subnormal result is rounded once. 5 fn fexp x f64 to f64 6 if ne x x 7 ret x 8 end 9 if gt x 709.`782712893384` 10 ret bitcast f64 ulong `9218868437227405312` 11 end 12 if lt x -745.`1332191019412` 13 ret 0.0f64 14 end 15 kf = mul x 1.`4426950408889634` 16 if ge kf 0.0 17 kf = add kf 0.5 18 else 19 kf = sub kf 0.5 20 end 21 k = long kf 22 fk = f64 k 23 r = sub sub x mul fk 0.`6931471803691238` mul fk 1.`9082149292705877e`-10 24 p = add mul r 1.`6059043836821613e`-10 2.`08767569878681e`-9 25 p = add mul p r 2.`505210838544172e`-8 26 p = add mul p r 2.`755731922398589e`-7 27 p = add mul p r 2.`7557319223985893e`-6 28 p = add mul p r 0.`0000248015873015873` 29 p = add mul p r 0.`0001984126984126984` 30 p = add mul p r 0.`001388888888888889` 31 p = add mul p r 0.`008333333333333333` 32 p = add mul p r 0.`041666666666666664` 33 p = add mul p r 0.`16666666666666666` 34 p = add mul p r 0.5 35 p = add mul p r 1.0 36 p = add mul p r 1.0 37 k1 = div k 2 38 k2 = sub k k1 39 s1 = bitcast f64 shl ulong add k1 1023 52 40 s2 = bitcast f64 shl ulong add k2 1023 52 41 ret mul mul p s1 s2 42 end 43 44 note natural log for every f64 x: NaN for x < 0 or NaN, -inf for 0, +inf for +inf. x = m 2^e with 45 note m in [sqrt(1/2), sqrt 2]; log m = 2 atanh(s), s = (m-1)/(m+1), series to s^23. 46 fn flog x f64 to f64 47 if ne x x 48 ret x 49 end 50 if lt x 0.0 51 ret bitcast f64 ulong `9221120237041090560` 52 end 53 if eq x 0.0 54 ret bitcast f64 ulong `18442240474082181120` 55 end 56 b = bitcast ulong x 57 if eq b `9218868437227405312` 58 ret x 59 end 60 e = long 0 61 if lt b `4503599627370496` 62 b = bitcast ulong mul x `18014398509481984`.0 63 e = long -54 64 end 65 e = add e sub long shr b 52 1023 66 m = bitcast f64 or and b `4503599627370495` `4607182418800017408` 67 if gt m 1.`4142135623730951` 68 m = mul m 0.5 69 e = add e 1 70 end 71 f = sub m 1.0 72 s = div f add f 2.0 73 z = mul s s 74 q = add mul z 0.`043478260869565216` 0.`047619047619047616` 75 q = add mul q z 0.`05263157894736842` 76 q = add mul q z 0.`058823529411764705` 77 q = add mul q z 0.`06666666666666667` 78 q = add mul q z 0.`07692307692307693` 79 q = add mul q z 0.`09090909090909091` 80 q = add mul q z 0.`1111111111111111` 81 q = add mul q z 0.`14285714285714285` 82 q = add mul q z 0.2 83 q = add mul q z 0.`3333333333333333` 84 q = add mul q z 1.0 85 lm = mul add s s q 86 fe = f64 e 87 ret add mul fe 0.`6931471803691238` add lm mul fe 1.`9082149292705877e`-10 88 end 89