flat assembler
Message board for the users of flat assembler.

 Index > Windows > Is wsprintfA redundant? Goto page Previous  1, 2
Author
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.
07 Apr 2021, 14:40
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.
07 Apr 2021, 14:53
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.
07 Apr 2021, 15:24
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area
Goto page Previous  1, 2

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum