Re: New proposal for math.e
Juergen Luethje wrote:
>
> This is my new proposal for a "math.e" standard include file,
> according to the recent discussion on this forum.
<snip>
global function log2 (object x)
-- logarithm base 2
-- in : (sequence of) real number(s) > 0
-- out: (sequence of) real number(s)
-- Note: This function returns _exact_ results for all integral
-- powers of 2 in the half-closed interval ]0,#FFFFFFFF]
if atom(x) then
if x = #20000000 then
return 29
elsif x = #80000000 then
return 31
else
return log(x)/LN2
end if
end if
for i = 1 to length(x) do
x[i] = log2(x[i])
end for
return x
end function
I'm curious about the special treatment of #20000000 and #80000000 in log2.
I assume that rounding errors give you imprecise answers? However, I
get the following imprecise results when taking out the special cases:
for i = 0 to 32 do
printf(1, "%d: %0.16g\n", i & log2( power( 2, i ) ))
end for
0: 0
1: 1
2: 2
3: 3
4: 4.000000000000001
5: 5.000000000000001
6: 6.000000000000001
7: 7.000000000000001
8: 8.000000000000002
9: 9.000000000000002
10: 10
11: 11
12: 12
13: 13
14: 14
15: 15
16: 16
17: 17
18: 18
19: 19
20: 20
21: 21
22: 22
23: 23
24: 24
25: 25.00000000000001
26: 26
27: 27.00000000000001
28: 28
29: 29.00000000000001
30: 30
31: 31.00000000000001
32: 32.00000000000001
|
Not Categorized, Please Help
|
|