Test integerness: Difference between revisions
Content deleted Content added
→{{header|J}}: adding input and output |
→Tcl: Added implementation |
||
Line 15:
<pre>False
True</pre>
=={{header|Tcl}}==
The simplest method of doing this is testing whether the value is equal to the value after casting it to a integral value.
<lang tcl>proc isNumberIntegral {x} {
expr {$x == entier($x)}
}
foreach x {3.14 7 1000000000000000000000} {
puts [format "%s: %s" $x [expr {[isNumberIntegral $x] ? "yes" : "no"}]]
}</lang>
{{out}}
<pre>
3.14: no
7: yes
1000000000000000000000: yes
</pre>
|