Page 1 of 1

Variable of type Double not acting as expected ( 1e-26 = 0 )

Posted: Thu Aug 23, 2012 11:16 pm
by HajoEhlers
Given:
PB 4.61 ( for linux )
LX: Ubuntu 10.04 LTS (64bit)

Problem: value of type Double not working as expected. Meaning a value of 1e-26 will be zero.

Example:

Code: Select all

value.d=1.602e-16   
Debug value
Debug value*value
Debug Pow(value, 2) 
Debug 1e-26
we get

Code: Select all

0.0000000000000001602
0.0
0.0
0.0
I think double should work from:
...
Double: +- 2.2250738585072013e-308 bis +- 1.7976931348623157e+308
...

Do i something wrong or is it a bug ?
Hajo

Re: Variable of type Double not acting as expected ( 1e-26 =

Posted: Thu Aug 23, 2012 11:24 pm
by IdeasVacuum
You have to format the output:

Code: Select all

value.d = 1.602e-16   
Debug StrD(value,40)
Debug StrD(value*value,40)
Debug StrD(Pow(value, 2),40)
Debug StrD(1e-26,40)

Re: Variable of type Double not acting as expected ( 1e-26 =

Posted: Thu Aug 23, 2012 11:27 pm
by HajoEhlers
Thanks a lot
Hajo

Re: Variable of type Double not acting as expected ( 1e-26 =

Posted: Thu Aug 23, 2012 11:39 pm
by STARGĂ…TE
you can use this function for scientific notation

Code: Select all

Procedure.s StrSci(Value.d, NumberDecimals=-1, Prefix.s="e")
	Protected String.s, Exponent.i, Log10.d
	If Value = 0
		Exponent = 0
	Else
		Log10 = Log10(Abs(Value))
		Exponent = Round(Log10, #PB_Round_Down)
		Value * Pow(10, -Exponent)
	EndIf
	Prefix + Str(Exponent)
	If NumberDecimals = -1
		String = StrD(Value)
	Else
		String = StrD(Value, NumberDecimals)
	EndIf
	If FindString(String, ".")
		String = RTrim(String, "0")
		String = RTrim(String, ".")
	EndIf
	ProcedureReturn String+Prefix
EndProcedure

Define value.d = 1.602e-16   
Debug StrSci(value)
Debug StrSci(value*value)

Re: Variable of type Double not acting as expected ( 1e-26 =

Posted: Thu Aug 23, 2012 11:45 pm
by HajoEhlers
Addendum

is there a way to get the real values also in the debugger window ? ( Variable Viewer )

tia
Hajo