Decimal floating point number to binary: Difference between revisions

m
→‎{{header|Phix}}: bsae 2 -> 2/4/8/16/32
m (→‎{{header|Phix}}: bsae 2 -> 2/4/8/16/32)
Line 1,093:
if d>0 then
res &= '.'
-- while d>0 do -- (see update below)
while d>0
and (find(base=,{2,4,8,16,32}) or length(res)<15) do
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 is guaranteed to
Base 2/4/8/16/32 are guaranteed to terminate anyway, but for other bases we need some limit - the 15 I opted for is completely arbitrary.
- the 15 that I opted for is completely arbitrary.
 
=={{header|Python}}==
7,806

edits