Click here to get back home

Difference between float, double and real?

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Difference between float, double and real? Wander 05-22-2008
Get Chitika Premium
Posted by Wander on May 22, 2008, 11:07 am
Please log in for more thread options
currently there are those functions is_float, is_double and is_real,
which do exactly the same as far as i can see
what surprises me is that $a = (float/double/real) 1; all work, while
with settype() only float and double work, and 'real' not.
now im wondering, is there any difference between those?

and if not, will they all keep existing in php6? or will php continue
with only one of them?

Posted by =?ISO-8859-15?Q?Iv=E1n_S=E1nch on May 22, 2008, 11:12 am
Please log in for more thread options
Wander wrote:

> what surprises me is that $a = (float/double/real) 1; [...]
> now im wondering, is there any difference between those?

The amount of memory they need.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

"Las religiones, como las luciérnagas, necesitan de oscuridad para brillar"
(Arthur Schopenhauer)

Posted by Wander on May 22, 2008, 11:18 am
Please log in for more thread options
On May 22, 5:12 pm, Iv=E1n S=E1nchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.org> wrote:
> The amount of memory they need.

thanks for your quick response, could you tell me which of the 3 takes
the most memory, and which of them needs the least?

Posted by =?ISO-8859-15?Q?Iv=E1n_S=E1nch on May 22, 2008, 3:55 pm
Please log in for more thread options
Wander wrote:

> On May 22, 5:12 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
> escomposlinux.-.punto.-.org> wrote:
>> The amount of memory they need.
>
> thanks for your quick response, could you tell me which of the 3 takes
> the most memory, and which of them needs the least?

It really depends on your platform and the configuration of your
interpreter/compiler, but the most common scenario is that floats are
single-precision 32-bit IEEE 754 floating numbers; reals are an alias for
doubles; and doubles are double-precision 64-bit IEEE 754 floating numbers.

I suggest you to drop by http://en.wikipedia.org/wiki/IEEE_754-1985 in order
to learn a bit more.

And, of course, you've earned yourself a RTFM for not reading this:
http://php.net/language.types.float

"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 (the 64 bit
IEEE format)."

Cheers,
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Proudly running Debian Linux with 2.6.24-1-amd64 kernel, KDE 3.5.9, and PHP
5.2.6-1 generating this signature.
Uptime: 21:49:42 up 22 days, 1:10, 3 users, load average: 1.04, 0.87,
0.67


Posted by ZeldorBlat on May 22, 2008, 11:29 am
Please log in for more thread options
> currently there are those functions is_float, is_double and is_real,
> which do exactly the same as far as i can see
> what surprises me is that $a = (float/double/real) 1; all work, while
> with settype() only float and double work, and 'real' not.
> now im wondering, is there any difference between those?
>
> and if not, will they all keep existing in php6? or will php continue
> with only one of them?

They're all the same. According to the manual, both is_real() and
is_double() are simply aliases for is_float(). Also, according to the
manual, the "type" parameter to settype() takes "float" since PHP
4.2.0 as the "double" variant was deprecated.

Similar ThreadsPosted
Double Vs. Float January 3, 2008, 5:18 pm
float reduced August 27, 2005, 10:43 pm
Format float May 14, 2006, 8:51 am
float to integer convertion September 21, 2006, 3:18 am
converting string to float February 15, 2007, 12:32 pm
problem querying a float column April 1, 2005, 8:30 am
Differentr Values for intval(float) February 18, 2006, 11:15 am
problems with float conversion from a string December 6, 2007, 10:02 am
unix time stamp as float instead of integer? May 23, 2005, 4:50 pm
MySql VCHAR column converted to float by PHP :-( March 1, 2006, 11:24 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap