How to output a Floating Point number on the screen if the precision is unknown ?
I wrote a fasm code to do that but it displays for example 28.0710391998291015625 instead of 28.07104
Here's my code ( will be optimized after :
Code: Select all
format elf
public ftol
public print_float
extrn print
extrn putchar
extrn itoa
half dd 0.5
i dd ?
tmp dd ?
e dd ?
ftol:
fld [half]
fld dword [esp+4]
fsub st0, st1
fld dword [esp+4]
faddp st2, st0
fistp [i]
mov eax, [i]
fistp [i]
add eax, [i]
sar eax, 1
ret
print_float2:
push ebp
mov ebp, esp
mov ebx, dword [esp+8]
mov [tmp], ebx
push [tmp]
call ftol
add esp, 4
mov [e], eax
push 0
push 0
push 10
push [e]
call itoa
add esp, 16
push eax
call print
add esp, 4
push '.'
call putchar
add esp, 4
fld [tmp]
fisub [e]
fst [tmp]
.do:
push 10
fimul dword [esp]
fst [tmp]
push [tmp]
call ftol
add esp, 4
mov [e], eax
push 0
push 0
push 10
push [e]
call itoa
add esp, 16
push eax
call print
add esp, 4
fisub [e]
fst [tmp]
ftst
fstsw ax
fwait
sahf
jnz .do
leave
ret
PS : itoa, print, and putchar are my own written functions, so they aren't standard .
Thanks
Thanks .