Page 1 of 1

#MinFloat/#MaxFlaot, #MinDouble/#MaxDouble...

Posted: Wed May 01, 2024 9:58 am
by jacdelad
Hi,
I wish there would be predefined constants for all numeric data types. I know I can define them by myself, but I feel like this should be built-in.

Re: #MinFloat/#MaxFlaot, #MinDouble/#MaxDouble...

Posted: Wed May 01, 2024 10:56 am
by STARGĂ…TE
And what should be the definition for #MinDouble in your opinion?

Code: Select all

#MinDouble = -1.7976931348623157081e308  ; smallest double greater than -Infinity
#MinDouble = 2.2250738585072013831e-308  ; smallest double greater than 0 with full precision
#MinDouble = 4.9406564584124654418e-324  ; smallest double greater than 0 with reduced precision

Re: #MinFloat/#MaxFlaot, #MinDouble/#MaxDouble...

Posted: Wed May 01, 2024 3:32 pm
by DarkDragon
I'm interested in the use case. Where are you actually going to use the minimum and maximum values? Are you sure infinity isn't better? E.g. looking for minimum/maximum of something could start with infinity/-infinity.

Re: #MinFloat/#MaxFlaot, #MinDouble/#MaxDouble...

Posted: Wed May 01, 2024 4:28 pm
by jacdelad
@STARGATE: Then the help is incorrect:
The exact range of values, which can be used with floats and doubles to get correct results from arithmetic operations, looks as follows:
Float: +- 1.175494e-38 till +- 3.402823e+38
Double: +- 2.2250738585072013e-308 till +- 1.7976931348623157e+308
More information about the 'IEEE 754' standard you can get on Wikipedia.
...or I miss something. Still, it would make sense for word, byte...

@DarkDragon: I'm using Doubles for my Gerber Module. Somtimes I have to find the lowest value from some (not predefined) operations. So initially I want to assign the highest value to my double. I surely can select a simply very high value, but using the highest value possible is much more elegant.

Re: #MinFloat/#MaxFlaot, #MinDouble/#MaxDouble...

Posted: Wed May 01, 2024 8:16 pm
by DarkDragon
jacdelad wrote: Wed May 01, 2024 4:28 pm@DarkDragon: I'm using Doubles for my Gerber Module. Somtimes I have to find the lowest value from some (not predefined) operations. So initially I want to assign the highest value to my double. I surely can select a simply very high value, but using the highest value possible is much more elegant.
That's exactly where you'd use Infinity, e.g.

Code: Select all

Minimum.d = Infinity()
ForEach Vertex()
  If Vertex()\X < Minimum
     Minimum = Vertex()\X
  EndIf
Next

Debug Minimum
For maximum you'd use -Infinity() as initial value.

Special floating point numbers according to IEEE754

Re: #MinFloat/#MaxFlaot, #MinDouble/#MaxDouble...

Posted: Thu May 02, 2024 3:18 am
by jacdelad
Ah ok, that makes sense. Thanks for the hint.