Hickerson series of almost integers: Difference between revisions

Forth version added
(Add Rust implementation)
(Forth version added)
Line 571:
</pre>
 
=={{header|Forth}}==
{{works with|4tH v3.64.0}}
4tH has two different floating point libraries. This version works with both of them.
<lang forth>[UNDEFINED] ANS [IF]
include lib/fp1.4th \ Zen float version
include lib/zenfprox.4th \ for F~
include lib/zenround.4th \ for FROUND
include lib/zenfln.4th \ for FLN
[ELSE]
include lib/fp3.4th \ Zen float version
include lib/flnflog.4th \ for FLN
[THEN]
 
include lib/fast-fac.4th \ for FACTORIAL
 
fclear \ initialize floating point
float array ln2 2 s>f fln latest f! \ precalculate ln(2)
\ integer exponentiation
: pow >r fdup r> 1 ?do fover f* loop fnip ;
: hickerson dup >r factorial s>f ln2 f@ r> 1+ pow fdup f+ f/ ;
: integer? if ." TRUE " else ." FALSE" then space ;
\ is it an integer?
: first17
18 1 do \ test hickerson 1-17
i hickerson i 2 .r space fdup fdup fround
s" 1e-1" s>float f~ integer? f. cr
loop \ within 0.1 absolute error
;
 
first17</lang>
{{out}}
<pre>
1 TRUE 1.040684490502803898935311338275660267
2 TRUE 3.002780707156905443502020333103288357
3 TRUE 12.99629050527696646223788568296556096
4 TRUE 74.99873544766160012772833377667325825
5 TRUE 541.0015185164235075700145797037460679
6 TRUE 4683.001247262257437188665462676039563
7 TRUE 47292.99873131462390491745677950570536
8 TRUE 545834.9979074851670685196268094270956
9 TRUE 7087261.001622899120996912279845689616
10 TRUE 102247563.0052710420113696743135681269
11 TRUE 1622632572.997550049857744575227371627
12 TRUE 28091567594.98157244080652083799015398
13 TRUE 526858348381.0012482880251816804368039
14 TRUE 10641342970443.08453196701499663939019
15 TRUE 230283190977853.0374369606024567600908
16 FALSE 5315654681981354.513099343419112934817
17 FALSE 130370767029135900.4585722365605854515
</pre>
=={{header|Fortran}}==
<lang fortran>program hickerson
374

edits