Test integerness: Difference between revisions

(→‎{{header|Quackery}}: Added extra credit)
Line 1,977:
Quackery uses bignums ("numbers" in the Quackery nomenclature) and comes with a bignum rational ("vulgars") arithmetic library. Quackery does not differentiate between two numbers on the stack and one vulgar. <code>v-is-num</code> returns true (1) if the top two numbers on the stack can be interpreted as a vulgar with no fractional component, and false (0) otherwise.
 
<code>approx0=approxint</code> is the extra credit version. Tolerance is specified to a number of decimal places.
 
<lang Quackery> [ $ "bigrat.qky" loadfile ] now!
[ mod not ] is v-is-num ( n/d --> b )
 
[ 1+ dip [ proper rot drop ]
[ mod not ] is v-is-num ( n/d --> b )
[ dip [10 properswap rot** dropround 0 1 ] approx=v-is-num ] is approx0=approxint ( n/d n --> b )</lang>
 
[ dip [ proper rot drop 0 1 ] approx= ] is approx0= ( n/d n --> b )</lang>
 
{{out}}
Line 1,999 ⟶ 2,000:
Stack empty.
 
/O> $ "25.000000" $->v drop 3 approx0=approxint iff [ say "true" ] else [ say "false" ] cr
... $ "24.999999" $->v drop 3 approx0=approxint iff [ say "true" ] else [ say "false" ] cr
... $ "25.000100" $->v drop 3 approx0=approxint iff [ say "true" ] else [ say "false" ] cr
...
true
false
true
false
 
Stack empty.</pre>
1,462

edits