Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

floating-point #1

Open
hex11o opened this issue Jan 23, 2020 · 3 comments
Open

floating-point #1

hex11o opened this issue Jan 23, 2020 · 3 comments

Comments

@hex11o
Copy link
Owner

hex11o commented Jan 23, 2020

IEEE-754

@hex11o
Copy link
Owner Author

hex11o commented Jan 23, 2020

Read

该标准的double格式,就是js里浮点数的存储方式。
format

  1. sign: 第一位是符号位,正负数(-1)^sign
  2. exponent: 2~12bit 共11位,可以是带正负的指数(-1022~1023)或是 不带正负的整数(0~2047)。
  3. significand precision: 13~64位共52位, 用来记录精度(2^−53 ≈ 1.11 × 10^−16)。

指数位,预设值是1023

  • 指数的两种特殊情况(F指精度部分):
    1. 11个0, represent signed zero (if F = 0) or subnormals(if F != 0)
    2. 11个1, 代表无限(if F = 0) or NaNs(if F != 0)
      最终结果是通过正负数* 指数幂*精度位数据。
  1. (-1)^sign2^(e-1023)(1.fraction)
  2. (-1)^sign2^(e-1023)(0.fraction) when subnormals

@hex11o
Copy link
Owner Author

hex11o commented Jan 23, 2020

Write

比如说12.3

  1. sign = 0
  2. 先看fraction
    1. 先拆成整数和小数部分12 = 1100 / 0.3
    2. 小数部分* 2 mod 1,直到余0 或位数不够, 存模(0.3 * 2 = 0.6, 存0继续; 0.6 * 2 = 1.2, 存1,0.2继续,0.4, 0.8, 存1,0.6, 0.2 )
    3. 1100.0 1001 1001………………
  3. exponent:将上面的binary变为科学计数, 1.1000 1001.…………* 2^3

最后存的就是:0/10000000010/1000 1001 1001………………

@hex11o
Copy link
Owner Author

hex11o commented Jan 23, 2020

浮点操作工具

@hex11o hex11o changed the title #1 floating-point floating-point Sep 12, 2020
@hex11o hex11o mentioned this issue Jun 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant