Skip to content

Commit c60f6c9

Browse files
committed
update post: IEEE-754
1 parent bfd629a commit c60f6c9

File tree

14 files changed

+83
-80
lines changed

14 files changed

+83
-80
lines changed
Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
+++
2-
date = '2025-08-19T8:00:00+08:00'
2+
date = '2025-08-18T8:00:00+08:00'
33
draft = false
44
title = 'IEEE-754 Introduce'
5-
tags = ['c']
5+
tags = ['C']
66
+++
77
IEEE 754 标准数值类型及分类
88

@@ -33,62 +33,65 @@ value = (-1)^(sign) x mantissa x 2^(exponent)
3333

3434
### 浮点数的分类 Categories
3535
以 64 精度为例
36-
| 部分 | 位数 | 描述 |
37-
| :---------------------- | :- | :---------------------- |
38-
| 符号位(sign) | 1 | 0 表示正数,1 表示负数 |
39-
| 阶码(exponent) | 11 | 偏移量(bias)为 1023,表示数值的量级 |
40-
| 尾数(fraction / mantissa) | 52 | 有效数字,不包括隐藏位 |
36+
| 部分 | 位数 | 描述 |
37+
| :------------------------ | :--- | :---------------------- |
38+
| 符号位(sign) | 1 | 0 表示正数,1 表示负数 |
39+
| 阶码(exponent) | 11 | 偏移量(bias)为 1023,表示数值的量级 |
40+
| 尾数(fraction / mantissa) | 52 | 有效数字,不包括隐藏位 |
4141

4242
浮点数的表示公式:
4343
```
4444
value = (-1)^sign x (1 + fraction) x 2^(exponent - bias)
4545
```
4646

47-
1. 正常数 Normalized numbers
47+
- 正常数 Normalized numbers
4848
- 阶码 exponent: 不全为0, 也不全为1, [1, 2^11-2]
49-
- 尾数 fraction: 隐含1, [0, 1 - 2^(-52)], (52位全1 位 1 - 2^(-52))
49+
- 尾数 fraction: 隐含1, [0, 1 - 2^-52], (52位全1 位 1 - 2^-52)
5050
```
51-
value = (-1)^sign x (1 + fraction) x 2^(exp - 1023)
51+
value = (-1)^sign x (1 + fraction) x 2^(exponent - 1023)
5252
```
5353
其中, `bias = 2^(exponent - 1) - 1`, 这里为 1023
5454
55-
- 最大正常数: 阶码最大为 `1024*2-2 = 2046`, 尾数全为1 `1-2^(-52)`, 即 `( 1 + (1 - 2^(-52)) ) x 2^(2026-1023)`
55+
- 最大正常数: 阶码最大为 `1024*2-2 = 2046`, 尾数全为1 `1-2^-52`, 即 `( 1 + (1 - 2^-52) ) x 2^(2026-1023)`
5656
- 最小正常数: 阶码最小位 `1`, 尾数全为0, 即 `( 1 + 0 ) x 2^(1-1023)`
5757
58-
2. 非正规数 Subnormal numbers / Denormalized numbers
58+
- 非正规数 Subnormal numbers / Denormalized numbers
5959
- 阶码 exponent: 全0
60-
- 尾数 fraction: [0, 1-2^(-52)], 没有隐藏位1
60+
- 尾数 fraction: [0, 1-2^-52], 没有隐藏位1
6161
```
62-
value = (-1)^sign x (fraction) x 2^(1 - E_min)
62+
value = (-1)^sign x (fraction) x 2^(1 - bias)
6363
```
64-
其中, `E_min` 定义为 最小的正常数指数 = `1 - bias = -1022`
64+
非正规数指数紧接最小正常数, 使非正规数数值连续接近零
65+
6566
> 注意: 非正规数的指数并不是阶码减 bias 的直接结果(0−1023 = −1023), 而是约定使用最小正常数指数 `E_min = −1022`.
6667
> 这样可以让非正规数顺接正常数, 形成连续的可表示范围, 并支持渐进下溢.
6768
68-
- 最大非正规数: 阶码为0, 尾数全为1, 即 `( 1 - 2^(-52) ) x 2^(-1022)`
69-
- 最小非正规数: 阶码位0, 尾数最低位为1, 其他为0, 即 `( 2^(-52) x 2^(-1022) )`
69+
- 最大非正规数: 阶码为0, 尾数全为1, 即 `( 1 - 2^-52 ) x 2^(-1022)`
70+
- 最小非正规数: 阶码位0, 尾数最低位为1, 其他为0, 即 `( 2^-52 x 2^(-1022) )`
7071
71-
3. 零 0
72+
- 零 0
7273
- 符号 sign: 0/1 正负零
7374
- 阶码 exponent: 0
7475
- 尾数 fraction: 0
7576
76-
4. 无穷 infinity
77+
- 无穷 infinity
7778
- 符号sign: 0/1 正负无穷
7879
- 阶码 exponent: 2047 (全1)
7980
- 尾数 fraction: 0
8081
81-
5. 非数值 NaN
82+
- 非数值 NaN
8283
- 阶码 exponent: 2047 (全1)
8384
- 尾数 fraction != 0
8485
8586
表示未定义或非法运算, 如 0/0
8687
8788
88-
| 类别 | 符号位 (sign) | 阶码 (exponent) | 尾数 (fraction / mantissa) | 描述 |
89-
| :---------------- | :--------- | :------------ | :----------------------- | :-------------------- |
90-
| 正常数 | 0 或 1 | 1\~2046 | 0\~(1 − 2^-52) | 阶码非全 0/全 1,尾数隐含最高位 1 |
91-
| 非正规数 | 0 或 1 | 0 | 0\~(1 − 2^-52) | 阶码全 0,尾数非零,无隐藏位,接近 0 |
92-
| ±0 | 0 或 1 | 0 | 0 | 正零或负零 |
93-
| ±∞ | 0 或 1 | 2047 | 0 | 正无穷或负无穷 |
94-
| NaN (qNaN / sNaN) | 0 或 1 | 2047 | 非零 | 阶码全 1,尾数非零,表示无效或未定义运算 |
89+
| 类别 (categories) | 符号位 (sign) | 阶码 (exponent) | 尾数 (fraction / mantissa) | 描述 |
90+
| :---------------- | :------------ | :-------------- | :------------------------- | :--------------------------------------- |
91+
| 正常数 | 0 或 1 | \[1, 2046] | 1.f \[1, ..., 1.1...1] 即 [1.0, 2-ε) | 阶码非全0且非全1, 尾数隐含最高位1 |
92+
| 非正规数 | 0 或 1 | 全 0 | 0.f (0, ..., 0.1...1] 即 (0, 1.0-ε] | 阶码全0, 尾数非全0, 无隐藏位1, 接近0 |
93+
| ±0 | 0 或 1 | 全 0 | 全 0 | 阶码全0, 尾数全0 |
94+
| ±∞ | 0 或 1 | 全 1 [2047] | 全 0 | 阶码全1, 尾数全0 |
95+
| NaN (qNaN / sNaN) | 0 或 1 | 全 1 [2047] | 非全 0 | 阶码全1, 尾数非全0, 表示无效或未定义运算 |
96+
97+
> 注意: 非正规数的阶码虽然为全0, 但是计算时约定为 1-bias = 1-1023 = -1022, 而不是像正规数那样数 exponent - bias

public/archives/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@
5454
<span>19 posts total</span></div><div class="flex items-center gap-1"><svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v12a2 2 0 002 2z"/></svg>
5555
<span>Timeline view</span></div></div></header><div class=relative><div class="bg-border absolute top-0 bottom-0 left-4 w-0.5"></div><div class=mb-12><div class="relative mb-8 flex items-center"><div class="bg-primary absolute left-0 z-10 flex h-8 w-8 items-center justify-center rounded-full"><svg class="h-4 w-4 text-primary-foreground" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v12a2 2 0 002 2z"/></svg></div><div class=ml-12><h2 class="text-foreground text-2xl font-bold">2025</h2><p class="text-muted-foreground text-sm">19
5656
posts</p></div></div><div class="relative mb-8"><div class="relative mb-4 flex items-center"><div class="bg-accent border-background absolute left-2 z-10 h-4 w-4 rounded-full border-2"></div><div class=ml-12><h3 class="text-foreground text-lg font-semibold">August 2025</h3><p class="text-muted-foreground text-xs">19
57-
posts</p></div></div><div class="ml-12 space-y-3"><article class="group bg-card border-border hover:bg-accent/50 rounded-lg border p-4 transition-all duration-300"><div class="flex items-center justify-between gap-4"><div class="min-w-0 flex-1"><h4 class="text-foreground group-hover:text-primary mb-3 font-medium transition-colors duration-200"><a href=/posts/ieee-754-introduce/ class=block>IEEE-754 Introduce</a></h4><div class="text-muted-foreground flex items-center gap-4 text-xs"><div class="flex items-center gap-1"><svg class="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v12a2 2 0 002 2z"/></svg>
58-
<time datetime=2025-08-19>08-19</time></div><div class="flex items-center gap-1"><svg class="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3A9 9 0 113 12a9 9 0 0118 0z"/></svg>
59-
<span>3
60-
min</span></div></div></div></div></article><article class="group bg-card border-border hover:bg-accent/50 rounded-lg border p-4 transition-all duration-300"><div class="flex items-center justify-between gap-4"><div class="min-w-0 flex-1"><h4 class="text-foreground group-hover:text-primary mb-3 font-medium transition-colors duration-200"><a href=/posts/redis-string/ class=block>Redis String</a></h4><div class="text-muted-foreground flex items-center gap-4 text-xs"><div class="flex items-center gap-1"><svg class="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v12a2 2 0 002 2z"/></svg>
57+
posts</p></div></div><div class="ml-12 space-y-3"><article class="group bg-card border-border hover:bg-accent/50 rounded-lg border p-4 transition-all duration-300"><div class="flex items-center justify-between gap-4"><div class="min-w-0 flex-1"><h4 class="text-foreground group-hover:text-primary mb-3 font-medium transition-colors duration-200"><a href=/posts/redis-string/ class=block>Redis String</a></h4><div class="text-muted-foreground flex items-center gap-4 text-xs"><div class="flex items-center gap-1"><svg class="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v12a2 2 0 002 2z"/></svg>
6158
<time datetime=2025-08-19>08-19</time></div><div class="flex items-center gap-1"><svg class="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3A9 9 0 113 12a9 9 0 0118 0z"/></svg>
6259
<span>5
60+
min</span></div></div></div></div></article><article class="group bg-card border-border hover:bg-accent/50 rounded-lg border p-4 transition-all duration-300"><div class="flex items-center justify-between gap-4"><div class="min-w-0 flex-1"><h4 class="text-foreground group-hover:text-primary mb-3 font-medium transition-colors duration-200"><a href=/posts/ieee-754-introduce/ class=block>IEEE-754 Introduce</a></h4><div class="text-muted-foreground flex items-center gap-4 text-xs"><div class="flex items-center gap-1"><svg class="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v12a2 2 0 002 2z"/></svg>
61+
<time datetime=2025-08-18>08-18</time></div><div class="flex items-center gap-1"><svg class="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3A9 9 0 113 12a9 9 0 0118 0z"/></svg>
62+
<span>3
6363
min</span></div></div></div></div></article><article class="group bg-card border-border hover:bg-accent/50 rounded-lg border p-4 transition-all duration-300"><div class="flex items-center justify-between gap-4"><div class="min-w-0 flex-1"><h4 class="text-foreground group-hover:text-primary mb-3 font-medium transition-colors duration-200"><a href=/posts/designing-and-building-rest-apis/ class=block>Designing and Building REST APIs</a></h4><div class="text-muted-foreground flex items-center gap-4 text-xs"><div class="flex items-center gap-1"><svg class="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v12a2 2 0 002 2z"/></svg>
6464
<time datetime=2025-08-17>08-17</time></div><div class="flex items-center gap-1"><svg class="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3A9 9 0 113 12a9 9 0 0118 0z"/></svg>
6565
<span>8

0 commit comments

Comments
 (0)