flat assembler
Message board for the users of flat assembler.

Index > Windows > Is wsprintfA redundant?

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 624
Location: Russian Federation, Sochi
ProMiNick
interesting: is only 486 solution of converting float to string exists? or much faster to use fpu.
for example
for every 10 of exponent down
we could multiply float mantisa extended by 1 bit high with value $FA0000 (which is $7A0000 extended by 1 bit high)
we could multiply double mantisa extended by 1 bit high with value $1F400000000000 (which is $F400000000000 extended by 1 bit high)
what magic values? 1000/1024=0,9765625 represented with HEX $3FEF400000000000 for double & with $3F7A0000 for float.
we could see higher bits of multiplier are $FA and after goes zero bits
so fo representing bits sequence of mantisa of fraction we could multiply it(extended 1 bit hi) with $FA by ( (-exponent+9) div 10) times and we will got bits sequence of mantisa like it located not in fraction but in integer part.
count of multiplier bits are growing
1111 1010
1111 0100 0010 0100
1110 1110 0110 1011 0010 1000
1110 1000 1101 0100 1010 0101 0001 0000
1110 0011 0101 1111 1010 1001 0011 0001 1010 0000
1101 1110 0000 1011 0110 1011 0011 1010 0111 0110 0100 0000
1101 1000 1101 0111 0010 0110 1011 0111 0001 0111 0111 1010 1000 0000
1101 0011 1100 0010 0001 1011 1100 1110 1100 1100 1110 1101 1010 0001 0000 0000
1100 1110 1100 1011 1000 1111 0010 0111 1111 0100 0010 0000 0000 1111 0011 1010 0000 0000
redundant trailing zeroes could be skipped
...
I gues via fpu it would be esier and faster...
but it is only road to ugly conversion, in same time needed to test values above & below 1 less significant bit if some shorter by precision value will fit this range & will be closer to our value not to border values.
Post 07 Apr 2021, 14:40
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18007
Location: In your JS exploiting you and your system
revolution
Float-to-decimal-ASCII conversion is more complicated than just converting the integer part.

Don't forget about the fraction parts, and the QNANs, SNAN, denormals, infinities, single precision, double precision, extended precision, zeros (both of them), rounding modes, ...

And then add the output formats: scientific/standard notation, required number of decimal places, required precision, rounding (this is a different rounding than above), truncate or display trailing zeros, how to deal with NANs/infinities, etc., leading +/- signs, ...

So a good converter would need to support all of that, otherwise it will have limited utility.
Post 07 Apr 2021, 14:53
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 259
Location: Ukraine
Overclick
You're right, I just show what FPU does by fistp
I think that conversion is good enough to work with COM or other programming usual float data. Also it can be modified for more keys of course.
When number between -1 to 1 or 0 to 1 I use fimul to move it above zero point.
Post 07 Apr 2021, 15:24
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.