Get the App
SLTechnology News&Howtos  ›  Development  › 

What does php floating point mean?

Shulou Source: shulou.com Published: 2022-06-02 01:40:51 09月30日 Update

This article mainly introduces php floating point refers to what is meant, the text is very detailed, has a certain reference value, interested friends must read!

php Float refers to the Float type, also known as float, double, or real, and is defined using syntax such as "$a = 1.234;$b = 1.2e3;"; floating-point numbers have platform-dependent word lengths, although they usually have a maximum value of 1.8e308 and precision of 14 decimal digits.

Operating environment: Windows 7 system, PHP7.1 version, DELL G3 computer

What does PHP mean by floating point?

Float

Floating-point types (also known as floating-point float, double-precision double, or real) can be defined using any of the following syntax:

Formal representation of floating-point numbers (underscore not supported before PHP 7.4.0):

LNUM [0-9]+(_[0-9]+)*DNUM ([0-9]*(_[0-9]+)*[\.] {LNUM}) | ({LNUM}[\.] [0-9]*(_[0-9]+)*)EXPONENT_DNUM (({LNUM} | {DNUM}) [eE][+-]? {LNUM})

Floating-point numbers have platform-dependent word sizes, although they usually have a maximum value of 1.8e308 and precision of 14 decimal digits (64-bit IEEE format).

precision of floating-point numbers

Floating-point numbers have limited precision. Although PHP typically uses IEEE 754 double precision format depending on the system, the maximum relative error due to rounding is 1.11e-16. Non-elementary mathematical operations may give larger errors and account for error propagation when performing compound operations.

Furthermore, rational numbers such as 0.1 or 0.7, which can be accurately represented in decimal, cannot be accurately represented by the binary used internally, no matter how many mantissas they have, and therefore cannot be converted to binary format without losing a little precision. This can lead to confusing results: for example, floor((0.1+0.7)*10) usually returns 7 instead of the expected 8, because the internal representation of the result is something like 7.99999999999991118...

So never trust floating-point results to the last digit, and never compare two floating-point numbers for equality. If higher precision is really needed, use arbitrary precision math functions or gmp functions.

The above is "php floating point refers to what means" all the content of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!

Tags: Precision point floating point meaning maximum exact decimal format result error decimal binary content function peace and platform real number number mathematics maximum Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Tech Info NVidia Redmi Shulou Technology