Php Floating Point Calculation

Source: Internet
Author: User
I would like to ask if true and false are random or regular. Thank you.


I would like to ask if true and false are random or regular. Thank you.

Reply content:


I would like to ask if true and false are random or regular. Thank you.

Refer to a blog post I wrote earlier.

Code mystery (4)-floating point number (from surprise to thinking)

Many floating point numbers cannot be expressed in the computer, and some can be expressed, but cannot be accurately expressed.

In addition, if you want to perform floating point calculation in PHP, you need to use Binary Calculator, that is, BCMath extension.

Using the round function, see: http://www.tantengvip.com/2015/08/php-float/

If the float/double format defined by IEEE754 is used, unfortunately, 0.1 cannot be precisely stored, because the decimal point cannot be accurately expressed simply in binary format (if you don't believe it, try it ~). Similarly, in the calculation of floating point numbers, it is inevitable to lose some precision.

For details about the cause, refer to shell technology: low-level Android calculator error? It's all binary!

For reference: http://acm.whu.edu.cn/starter/problem...

We recommend that you buy this book "deep understanding of computer systems". The second chapter introduces how data is stored on computers.

Thanks for the reliable answers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.