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

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
jacdelad
Addict
Addict
Posts: 1993
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

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

Post 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.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

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

Post 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
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
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

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

Post 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.
bye,
Daniel
User avatar
jacdelad
Addict
Addict
Posts: 1993
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

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

Post 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.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

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

Post 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
bye,
Daniel
User avatar
jacdelad
Addict
Addict
Posts: 1993
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

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

Post by jacdelad »

Ah ok, that makes sense. Thanks for the hint.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Post Reply