For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > October 2006 > Determine largest possible float value









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Determine largest possible float value
Thomas Mlynarczyk

2006-10-30, 7:02 pm

Hi,

I'm looking for a way to determine the largest possible (finite) value a
float variable can have on the platform where the script is running. There
seems to be no function or predefined constant (like PHP_INT_MAX for
integers). I was thinking maybe I could pack() some test data and unpack()
the first x bits of it as float, but I'm not sure if this would work.

Any ideas?

Greetings,
Thomas


Koncept

2006-10-30, 7:03 pm

In article <ehlpqn$ttd$01$1@news.t-online.com>, Thomas Mlynarczyk
<thomas@mlynarczyk-webdesign.de> wrote:

> Hi,
>
> I'm looking for a way to determine the largest possible (finite) value a
> float variable can have on the platform where the script is running. There
> seems to be no function or predefined constant (like PHP_INT_MAX for
> integers). I was thinking maybe I could pack() some test data and unpack()
> the first x bits of it as float, but I'm not sure if this would work.
>
> Any ideas?
>
> Greetings,
> Thomas
>
>


The docs say the following (Ch11. Types "Floating point numbers"):

"The size of a float is platform-dependent, although a maximum of
~1.8e308 with a precision of roughly 14 decimal digits is a common
value (that's 64 bit IEEE format)."

Hope this helps you somewhat.

--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche
Thomas Mlynarczyk

2006-10-30, 7:03 pm

Also sprach Koncept:

"The size of a float is platform-dependent, although a maximum of
> ~1.8e308 with a precision of roughly 14 decimal digits is a common
> value (that's 64 bit IEEE format)."
> Hope this helps you somewhat.


Sorry - not quite. I was actually looking for a piece of code which finds
out how a float is stored (mantissa and exponent size) on a given system, so
I can know the largest finite value that would fit in a float on that
system. Something like PHP_INT_MAX but for floats.

Greetings,
Thomas


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com