News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

How do you print a floating point number?

Started by nixeagle, May 09, 2012, 02:31:22 AM

Previous topic - Next topic

nixeagle

Alright, working on showing standard deviations and mean clocks for the timing program I'm working on in http://www.masm32.com/board/index.php?topic=18787.0 . My problem is printing the floating point value from the floating point stack to standard out. What do you guys do?


hutch--

Convert it to string then point it where you like.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

nixeagle

Quote from: hutch-- on May 09, 2012, 02:38:54 AM
Convert it to string then point it where you like.
:lol, I was kinda hoping someone would have already done the "convert it to a string" part. That is the actual work! :wink.

P1

Quote from: nixeagle on May 09, 2012, 02:52:55 AM
Quote from: hutch-- on May 09, 2012, 02:38:54 AM
Convert it to string then point it where you like.
:lol, I was kinda hoping someone would have already done the "convert it to a string" part. That is the actual work! :wink.
I would use the "Search" Box.  This is not that original of a problem.

Regards, P1  :8)

dedndave

there are some past threads regarding this function
as i recall, Jochen had a nice fast routine (jj2007)
so - you can use the Advanced Search options - and narrow the search to posts by jj2007

also...
Ray's FPU library has a routine for this
http://www.ray.masmcode.com/

nixeagle

Alright, I'll dig up jj2007's thing. I'd like to keep this as simple as possible and not include a ton of extra libraries if I can avoid it. This was meant to be small and simple ::). I'm almost done with the work of tracking errors through all the calculations so the final result has the correct error associated with it. That'll make it so we can say this result is 20 ticks +/- 2 ticks (or this result is 20 ticks +/- 10%), whichever format you guys end up liking more :)

nixeagle

:( facepalm :(

Quote
[attachment deleted by admin]

for jj2007's float$ macro listed in http://www.masm32.com/board/index.php?topic=9756.0

jj2007, you happen to still have a copy? :bg

dedndave

oh - i forgot to mention...
the crt has printf, as well as other similar functions, that can do it
no muss no fuss   :P

well - you have to know a little about formatting printf

nixeagle

Quote from: dedndave on May 09, 2012, 04:29:34 AM
oh - i forgot to mention...
the crt has printf, as well as other similar functions, that can do it
no muss no fuss   :P

well - you have to know a little about formatting printf

Whichever works. I don't know what you mean by crt though. I honestly just want to display this and move on ::) as I'm almost down to a "real" version of this :bg. For example, my current output is:

Running testit_long_baseline.0
Running long_testit_div.: [1276 .. 1276 .. 1280] - Variance: 0 ticks^2 - SDev: 0 ticks.
Running long_testit_cdiv.: [214 .. 257 .. 258] - Variance: 27 ticks^2 - SDev: 5 ticks.
Please subtract testit_long_baseline time from both, then divide by 128.
Running testit_baseline.0
Running testit_div.: [311 .. 311 .. 311] - Variance: 0 ticks^2 - SDev: 0 ticks.
Running testit_cdiv.: [44 .. 45 .. 50] - Variance: 8 ticks^2 - SDev: 3 ticks.
Please subtract testit_baseline time from both, then divide by 32.
Running short_testit_baseline.1
Running short_testit_div.: [39 .. 39 .. 39] - Variance: 1 ticks^2 - SDev: 1 ticks.
Running short_testit_cdiv.: [3 .. 7 .. 8] - Variance: 8 ticks^2 - SDev: 3 ticks.


SDev in the above really should be a floating point number. :wink And really so should the middle number in those ranges.

I'd like to get that spam down to just 6 lines, and possibly even just 2, with the different long, normal, short functions handled automatically. :U

dedndave

crt - msvcrt - microsoft visual C runtime library
if you use \masm32\include\masm32rt.inc, the appropriate files are already included

dedndave

http://msdn.microsoft.com/en-us/library/wc7014hz%28v=vs.71%29.aspx
http://msdn.microsoft.com/en-us/library/56e442dc%28v=vs.71%29.aspx

it looks like you want one of these "type" specifiers...
e, E, f, g, G
they will display double-precision (qwords) in various ways
http://msdn.microsoft.com/en-us/library/hf4y5e3w%28v=vs.71%29.aspx
i seem to recall that MichaelW gave an example a while back


nixeagle

Quote from: nixeagle on May 09, 2012, 04:56:58 AM
Quote from: dedndave on May 09, 2012, 04:44:51 AM
http://msdn.microsoft.com/en-us/library/wc7014hz%28v=vs.71%29.aspx
http://msdn.microsoft.com/en-us/library/56e442dc%28v=vs.71%29.aspx

it looks like you want one of these "type" specifiers...
e, E, f, g, G
they will display double-precision (qwords) in various ways
http://msdn.microsoft.com/en-us/library/hf4y5e3w%28v=vs.71%29.aspx
i seem to recall that MichaelW gave an example a while back

Found it :dance:. http://www.masm32.com/board/index.php?topic=18797.msg159144#msg159144

Well that sucks, printf does not output to CygWin's terminal, only to cmd.exe :(. Hopefully jj2007 still has a copy of float$.

hutch--

Have a look at Ray's version, his FP stuff has been very reliable for years.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

nixeagle

Quote from: hutch-- on May 09, 2012, 05:20:45 AM
Have a look at Ray's version, his FP stuff has been very reliable for years.

Alright, I'll do so tomorrow, this is basically the last thing I need to do :). I have all the mathematics and error calculations propagating correctly to account for possible deviations in both the baseline measurements and the test function measurements.

Thanks all :)