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

Just starting out? Need help? Post your questions and find answers here.
HajoEhlers
New User
New User
Posts: 8
Joined: Fri Aug 13, 2010 5:49 pm
Location: Germany
Contact:

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

Post 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
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

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

Post 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)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
HajoEhlers
New User
New User
Posts: 8
Joined: Fri Aug 13, 2010 5:49 pm
Location: Germany
Contact:

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

Post by HajoEhlers »

Thanks a lot
Hajo
Enlightenment is a state of knowledge but even infinite knowledge does not lead to enlightenment.
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

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

Post 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)
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
HajoEhlers
New User
New User
Posts: 8
Joined: Fri Aug 13, 2010 5:49 pm
Location: Germany
Contact:

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

Post by HajoEhlers »

Addendum

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

tia
Hajo
Enlightenment is a state of knowledge but even infinite knowledge does not lead to enlightenment.
Post Reply