Hickerson series of almost integers: Difference between revisions

Added Wren
(Added Wren)
Line 2,273:
End</lang>
(untested)
 
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
{{libheader|Wren-big}}
This is a tricky task for Wren which doesn't have arbitrary precision float or decimal but does have (via the above module) BigInt.
 
I've therefore used the most accurate value I could find for log2 (63 digit accuracy), represented this as a BigInt, and worked from there.
<lang ecmascript>import "/math" for Int
import "/fmt" for Fmt
import "/big" for BigInt
 
var hickerson = Fn.new { |n|
var fact = BigInt.new(Int.factorial(n)) // accurate up to n == 18
var ln2 = BigInt.new("693147180559945309417232121458176568075500134360255254120680009") // 63 digits
var mult = BigInt.new("1e64").pow(n+1) // 64 == ln2 digit count + 1
return fact * mult /(BigInt.two * ln2.pow(n+1))
}
 
System.print("Values of h(n), truncated to 1 dp, and whether 'almost integers' or not:")
for (i in 1..17) {
var h = hickerson.call(i).toString
var hl = h.count
var k = hl - i - 1
var ai = (h[k] == "0" || h[k] == "9")
var s = h[0...k] + "." + h[k]
Fmt.print("$2d: $20s $s", i, s, ai)
}</lang>
 
{{out}}
<pre>
Values of h(n), truncated to 1 dp, and whether 'almost integers' or not:
1: 1.0 true
2: 3.0 true
3: 12.9 true
4: 74.9 true
5: 541.0 true
6: 4683.0 true
7: 47292.9 true
8: 545834.9 true
9: 7087261.0 true
10: 102247563.0 true
11: 1622632572.9 true
12: 28091567594.9 true
13: 526858348381.0 true
14: 10641342970443.0 true
15: 230283190977853.0 true
16: 5315654681981354.5 false
17: 130370767029135900.4 false
</pre>
 
=={{header|zkl}}==
9,485

edits