Page 2 of 2
Re: Printing floating point numbers with exponents.
Posted: Wed Feb 01, 2012 10:18 am
by wilbert
skywalk wrote:I couldn't get your last asm version SciStrD() to run - Operand size error?
I made a few improvements (see above for updated code).
Maybe it solves the problem. I'm not able to replicate it.
I tried both x86 and x64 and it works fine here.
Re: Printing floating point numbers with exponents.
Posted: Wed Feb 01, 2012 5:02 pm
by skywalk
Sorry, it ran once with debugger on, but not without.
My only compiler option is #PB_Compiler_unicode.
PB461b1 x86.
Re: Printing floating point numbers with exponents.
Posted: Wed Feb 01, 2012 5:33 pm
by wilbert
skywalk wrote:Sorry, it ran once with debugger on, but not without.
Strange that there's a difference.
I made a small change and think it should be working now.
Re: Printing floating point numbers with exponents.
Posted: Wed Feb 01, 2012 6:34 pm
by skywalk
Cool, runs now and is 2% faster overall.
But, weird bug only if 1st call to sciStrD(0,6,1) contains a 0?
Code: Select all
; Data.s StrDe(S,6) StrDsci(S,6) sciStrD(S,6)
Data.s "0" ;[ 0] [ 0.000000e+0] [ 0.000000e310] ;<-- This 'e310' goes away if called later?
Data.s "0.0" ;[ 0] [ 0.000000e+0] [ 0.000000e0]
Data.s "+0e0" ;[ 0] [ 0.000000e+0] [ 0.000000e0]
Data.s "+0.0e0" ;[ 0] [ 0.000000e+0] [ 0.000000e0]
Data.s "+0.0e+0" ;[ 0] [ 0.000000e+0] [ 0.000000e0]
Data.s "1" ;[ 1.00000e+0] [ 10.000000e-1] [ 1.000000e+0]
Data.s "1.1" ;[ 1.10000e+0] [ 1.100000e+0] [ 1.100000e+0]
Data.s "0.1" ;[ 100.000e-3] [ 10.000000e-2] [ 1.000000e-1]
Data.s "11" ;[ 11.0000e+0] [ 1.100000e+1] [ 1.100000e+1]
Data.s "111" ;[ 111.000e+0] [ 1.110000e+2] [ 1.110000e+2]
Data.s "10" ;[ 10.0000e+0] [ 1.000000e+1] [ 1.000000e+1]
Data.s "100" ;[ 100.000e+0] [ 1.000000e+2] [ 1.000000e+2]
Data.s "1000" ;[ 1.00000e+3] [ 1.000000e+3] [ 1.000000e+3]
Data.s "1000000" ;[ 1.00000e+6] [ 1.000000e+6] [ 1.000000e+6]
Data.s "999" ;[ 999.000e+0] [ 9.990000e+2] [ 9.990000e+2]
Data.s "-999" ;[-999.000e+0] [-9.990000e+2] [-9.990000e+2]
Data.s "-3.5e-20" ;[-35.0000e-21] [-3.500000e-20] [-3.500000e-20]
Re: Printing floating point numbers with exponents.
Posted: Wed Feb 01, 2012 7:41 pm
by wilbert
skywalk wrote:Cool, runs now and is 2% faster overall.
But, weird bug only if 1st call to sciStrD(0,6,1) contains a 0?
The bug should be fixed now.
For your engineering notation, maybe a real fixed length would be nice.
If support would be limited from 1e-99 to 1e+99, you could make the exponent always two digits.
Like 1.23456e-06
Re: Printing floating point numbers with exponents.
Posted: Wed Feb 01, 2012 7:53 pm
by Little John
skywalk wrote:Cool, runs now and is 2% faster overall.
And a maximum of 2% of the forum members are able to understand that code.
Regards, LJ
Re: Printing floating point numbers with exponents.
Posted: Wed Feb 01, 2012 7:59 pm
by wilbert
Little John wrote:And a maximum of 2% of the forum members are able to understand that code.

To me it's like a puzzle. I learned some new things creating the code and that's the fun for me.
Most of the times ASM isn't required on modern computers since they are fast enough.
Re: Printing floating point numbers with exponents.
Posted: Wed Feb 01, 2012 8:01 pm
by skywalk
wilbert wrote:For your engineering notation, maybe a real fixed length would be nice.
If support would be limited from 1e-99 to 1e+99, you could make the exponent always two digits.
Like 1.23456e-06
Yeah, I thought about forcing 2 exponent digits, but my data did not exceed "nano" or "giga" so e±9 is fine for me. Using "±xxx.yyyye±z" format, any number I print as a string can be retrieved with consistent numeric accuracy.
Little John wrote:And a maximum of 2% of the forum members are able to understand that code.

Re: Printing floating point numbers with exponents.
Posted: Thu Feb 02, 2012 12:05 am
by akj
@wilbert:
Thank you for the fix which seems to have solved the problem.
(I don't have any better solution of my own.)
Re: Printing floating point numbers with exponents.
Posted: Thu Feb 02, 2012 11:12 pm
by Psychophanta
This is the function i use since long time for this issue:
Code: Select all
Procedure$ StrE(fp.d,dec.b=14)
;Devuelve cadena alfanumérica en formato de notación científica
Protected E.b,neg.b=0
If dec<0:dec=0:ElseIf dec>20:dec=20:EndIf;<- Sanity check
E=Round(Log10(Abs(fp)),#PB_Round_Down)
If E
fp*Pow(10,-E)
ProcedureReturn RTrim(RTrim(StrD(fp,dec),"0"),".")+"E"+Str(E)
EndIf
ProcedureReturn RTrim(RTrim(StrD(fp,dec),"0"),".")
EndProcedure