PHP learning Records (float type ).? Php $ a1.234; $ b1.2e3; $ c7E-10 ;? Regular expression: Floating point: [0-9] + double precision: ([0-9] [.] {LNUM}) | ({LNUM} [.] [0-9] *) exponential expression: [+-]? ({LNUM} | {DNU $ A = 1.234;
$ B = 1.2e3;
$ C = 7E-10;
?>
The regular expression is as follows:
Floating point: [0-9] +
Double precision: ([0-9] [.] {LNUM}) | ({LNUM} [.] [0-9] *)
Exponential expression: [+-]? ({LNUM} | {DNUM}) [eE] [+-]? {LNUM })
======================================
The php code for the maximum floating point number is as follows:
Function float_max ($ mul = 2, $ affine = 1 ){
$ Max = 1; $ omax = 0;
While (string) $ max! = 'Inf ') {$ omax = $ max; $ max * = $ mul ;}
For ($ I = 0; $ I <$ affine; $ I ++ ){
$ Pmax = 1; $ max = $ omax;
While (string) $ max! = 'Inf '){
$ Omax = $ max;
$ Max + = $ pmax;
$ Pmax * = $ mul;
}
}
Return $ omax;
}
Echo "maximum floating point:"; var_dump (float_max ());
?>
======================================
The results are as follows (related to the platform ):
Maximum floating point: float (1.79769313486E + 308)
Precautions for floating point precision:
A simple decimal fraction, like 0.1 or 0.7, is converted to an internal binary format, which will result in loss of precision:
For example, floor (0.1 + 0.7) * 10) usually returns 7 instead of the expected 8, because the internal representation of this result is actually 7.9.
It is impossible to accurately express certain decimal scores with limited digits.
For example, the value of decimal 1/3 is 0.3.
So
1. Never believe that the result of a floating point number is accurate to the last digit,
2. Do not compare two floating point numbers for equality.
3. If higher precision is required, use any precision mathematical function or gmp function.
From PHP 5, if you try to convert an object to a floating point number, an E_NOTICE error will be issued.
Http://www.bkjia.com/PHPjc/371639.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/371639.htmlTechArticle? Php $ a = 1.234; $ B = 1.2e3; $ c = 7E-10 ;? Regular expression: Floating point: [0-9] + double precision: ([0-9] [.] {LNUM}) | ({LNUM} [.] [0-9] *) exponential expression: [+-]? ({LNUM} | {DNU...