Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does php support 64-bit ieee float

Tags:

php

I have done a deep reserach on this topic. But nothing is clear about this question. Can anyone help me out with this. http://www.php.net/manual/en/language.types.float.php Nothing is properly described this link prperly.

like image 668
Nishant Dongare Avatar asked Apr 15 '14 10:04

Nishant Dongare


People also ask

Is PHP a float?

The is_float() function checks whether a variable is of type float or not. This function returns true (1) if the variable is of type float, otherwise it returns false.

What is float number PHP?

PHP Floats A float is a number with a decimal point or a number in exponential form. 2.0, 256.4, 10.358, 7.64E+5, 5.56E-5 are all floats. The float data type can commonly store a value up to 1.7976931348623E+308 (platform dependent), and have a maximum precision of 14 digits.

How to make float number in PHP?

To convert string to float using PHP built-in function, floatval(), provide the string as argument to the function. The function will return the float value corresponding to the string content. $float_value = floatval( $string );


2 Answers

Yes it does.


From the PHP Manual..

The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). 64-bit platforms usually have a maximum value of about 9E18. PHP does not support unsigned integers. Integer size can be determined using the constant PHP_INT_SIZE, and maximum value using the constant PHP_INT_MAX since PHP 4.4.0 and PHP 5.0.5.

Also..

If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31 on 32-bit platforms and +/- 9.22e+18 = 2^63 on 64-bit platforms), the result is undefined, since the float doesn't have enough precision to give an exact integer result. No warning, not even a notice will be issued when this happens!

Exerpts from the inner links of PHP Manual to a 3rd Party site...

PHP is dynamically typed and will often convert implicitly between strings and floating-point numbers (which are platform-dependant, but typically IEEE 64 bit values). To force a value to floating-point, evaluate it in a numerical context: $foo = 0 + "10.5";

But if you are looking to play around with floats and precisions you need to use the GMP functions.

like image 140
Shankar Narayana Damodaran Avatar answered Sep 19 '22 22:09

Shankar Narayana Damodaran


Values stores inside https://github.com/php/php-src/blob/master/Zend/zend.h#L322

For float use double type. Size of float and double.

So, php support 64-bit ieee float.

like image 37
sectus Avatar answered Sep 17 '22 22:09

sectus