How is floating point stored? When does it matter?

2018-12-31 22:45发布

In follow up to this question, it appears that some numbers cannot be represented by floating point at all, and instead are approximated.

How are floating point numbers stored?

Is there a common standard for the different sizes?

What kind of gotchas do I need to watch out for if I use floating point?

Are they cross-language compatible (ie, what conversions do I need to deal with to send a floating point number from a python program to a C program over TCP/IP)?

-Adam

10条回答
美炸的是我
2楼-- · 2018-12-31 23:24

This article entitled "IEEE Standard 754 Floating Point Numbers" may be helpful. To be honest I'm not completely sure I'm understanding your question so I'm not sure that this is going to be helpful but I hope it will be.

查看更多
姐姐魅力值爆表
3楼-- · 2018-12-31 23:26

What I remember is a 32 bit floating point is stored using 24 bits for a actual number, and the remain 8 bits are used as a power of 10, determining where the decimal point is.

I'm a bit rusty on the subject tho...

查看更多
不流泪的眼
4楼-- · 2018-12-31 23:28

A thorough explanation of the issues surrounding floating point numbers is given in the article What Every Computer Scientist Should Know About Floating-Point Arithmetic.

查看更多
看淡一切
5楼-- · 2018-12-31 23:29

Yes there is the IEEE Standard for Binary Floating-Point Arithmetic (IEEE 754)

The number is split into three parts, sign, exponent and fraction, when stored in binary.

查看更多
登录 后发表回答