Test integerness: Difference between revisions
Content added Content deleted
(→{{header|Quackery}}: added test cases.) |
(→{{header|Quackery}}: Added extra credit) |
||
Line 1,977: | 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. |
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=</code> is the extra credit version. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
[ dip [ proper rot drop 0 1 ] approx= ] is approx0= ( n/d n --> b )</lang> |
|||
{{out}} |
{{out}} |
||
Line 1,983: | Line 1,989: | ||
Testing in the Quackery shell. |
Testing in the Quackery shell. |
||
⚫ | |||
⚫ | |||
... [ mod not ] is v-is-num ( n/d --> b ) |
|||
⚫ | |||
... $ "24.999999" $->v drop v-is-num iff [ say "true" ] else [ say "false" ] cr |
... $ "24.999999" $->v drop v-is-num iff [ say "true" ] else [ say "false" ] cr |
||
... $ "25.000100" $->v drop v-is-num iff [ say "true" ] else [ say "false" ] cr |
... $ "25.000100" $->v drop v-is-num iff [ say "true" ] else [ say "false" ] cr |
||
Line 1,991: | Line 1,995: | ||
true |
true |
||
false |
false |
||
false |
false |
||
Stack empty. |
|||
/O> $ "25.000000" $->v drop 3 approx0= iff [ say "true" ] else [ say "false" ] cr |
|||
... $ "24.999999" $->v drop 3 approx0= iff [ say "true" ] else [ say "false" ] cr |
|||
... $ "25.000100" $->v drop 3 approx0= iff [ say "true" ] else [ say "false" ] cr |
|||
... |
|||
true |
|||
false |
|||
true |
|||
Stack empty.</pre> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |