Decimal floating point number to binary: Difference between revisions
Content deleted Content added
→{{header|dc}}: bc |
m →{{header|Phix}}: bsae 2 -> 2/4/8/16/32 |
||
Line 1,093:
if d>0 then
res &= '.'
while d>0
and (find(base
d *= base
integer digit = floor(d)
Line 1,166 ⟶ 1,165:
The truth of the matter is simply that you ''can'' extract a float to a binary text representation exactly,
in a way that you just cannot do for most other (ie non-power-2) bases.<br>
Update: Added a limiter for non-base-2 fractions, as per 1/3 -> 0.333 forever in decimal.
Base 2/4/8/16/32 are guaranteed to terminate anyway, but for other bases we need some limit
- the 15 that I opted for is completely arbitrary.
=={{header|Python}}==
|