简体   繁体   中英

Why it throws “Floating Point Exception” if I divide a floating number by zero?

As titled.

As I know about the floating-point number, if we try to divide a floating-point number by zero, the result could actually be a "∞", namely infinity. And it also could be represented in floating-point number format as I showed below. So, why does the Linux system need to raise an exception rather than just doing what I expected? (the exception is raised by the underlying system)

在此处输入图像描述

Dividing by 0 does not necessarily result in infinity. There's a good numberphile video that goes into this.

More importantly here, the IEEE 754 floating point standard (which is what most languages/cpus use) dictates that dividing by 0 should result in NaN, and many programming languages just turn this into an error.

This is not linux specific. I don't even think Linux itself can raise something called an exception, so this must be a higher-level language thing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM