Skip to content

Commit fbe1a07

Browse files
committed
更新
1 parent 445483b commit fbe1a07

File tree

3 files changed

+21
-134
lines changed

3 files changed

+21
-134
lines changed

Diff for: doc/exercises/frexp.ipynb

+5-132
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"- `x`:浮点值。\n",
2626
"- `expptr`:指向存储的整数指数的指针。\n",
2727
"\n",
28-
"{func}`frexp` 返回尾数。 如果 `x` 为 `0`,则该函数将返回 `0` 表示尾数和指数。 `NULL` 如果是 `expptr`,则调用无效的参数处理程序,如参数验证中所述。 如果允许执行继续,则该函数将 `errno` 设置为 `EINVAL` 并返回 `0`。\n",
28+
"{func}`frexp` 返回尾数。 如果 `x` 为 `0`,则该函数将返回 `0` 表示尾数和指数。如果 `expptr` 是 `NULL`,则调用无效的参数处理程序,如参数验证中所述。 如果允许执行继续,则该函数将 `errno` 设置为 `EINVAL` 并返回 `0`。\n",
2929
"\n",
3030
"```{note}\n",
3131
"`frexp` 函数将浮点值(`x`)分解为尾数(mantissa `m`)和指数(exponent,`n`),使绝对值 `m` 大于或等于 `0.5` 且小于 `1.0`,并且 $x = m * 2^n$。整数指数 `n` 存储在由 `expptr` 指向的位置。\n",
@@ -63,154 +63,27 @@
6363
]
6464
},
6565
{
66-
"cell_type": "code",
67-
"execution_count": 7,
66+
"cell_type": "markdown",
6867
"metadata": {
6968
"vscode": {
7069
"languageId": "c++"
7170
}
7271
},
73-
"outputs": [],
7472
"source": [
75-
"double x = 2.302585093;\n",
76-
"double y;\n",
77-
"\n",
78-
"y = exp(x);"
73+
"将双精度有效数字转换为整数有效数字,即将小数点放在第 31 位和第 30 位之间。这是通过将双精度值乘以 $2^{31}$,然后将其转换为 int 来实现的。"
7974
]
8075
},
8176
{
8277
"cell_type": "code",
83-
"execution_count": 10,
78+
"execution_count": 3,
8479
"metadata": {
8580
"vscode": {
8681
"languageId": "c++"
8782
}
8883
},
8984
"outputs": [],
9085
"source": [
91-
"double sigmoid(double x) {\n",
92-
" return 1/(1+exp(-x));\n",
93-
"}"
94-
]
95-
},
96-
{
97-
"cell_type": "code",
98-
"execution_count": 11,
99-
"metadata": {
100-
"vscode": {
101-
"languageId": "c++"
102-
}
103-
},
104-
"outputs": [
105-
{
106-
"data": {
107-
"text/plain": [
108-
"0.73105858"
109-
]
110-
},
111-
"execution_count": 11,
112-
"metadata": {},
113-
"output_type": "execute_result"
114-
}
115-
],
116-
"source": [
117-
"sigmoid(1)"
118-
]
119-
},
120-
{
121-
"cell_type": "code",
122-
"execution_count": 12,
123-
"metadata": {
124-
"vscode": {
125-
"languageId": "c++"
126-
}
127-
},
128-
"outputs": [
129-
{
130-
"data": {
131-
"text/plain": [
132-
"0.50000000"
133-
]
134-
},
135-
"execution_count": 12,
136-
"metadata": {},
137-
"output_type": "execute_result"
138-
}
139-
],
140-
"source": [
141-
"sigmoid(0)"
142-
]
143-
},
144-
{
145-
"cell_type": "code",
146-
"execution_count": 13,
147-
"metadata": {
148-
"vscode": {
149-
"languageId": "c++"
150-
}
151-
},
152-
"outputs": [
153-
{
154-
"data": {
155-
"text/plain": [
156-
"2.0000000"
157-
]
158-
},
159-
"execution_count": 13,
160-
"metadata": {},
161-
"output_type": "execute_result"
162-
}
163-
],
164-
"source": [
165-
"1/(0.5)"
166-
]
167-
},
168-
{
169-
"cell_type": "code",
170-
"execution_count": 14,
171-
"metadata": {
172-
"vscode": {
173-
"languageId": "c++"
174-
}
175-
},
176-
"outputs": [
177-
{
178-
"data": {
179-
"text/plain": [
180-
"0"
181-
]
182-
},
183-
"execution_count": 14,
184-
"metadata": {},
185-
"output_type": "execute_result"
186-
}
187-
],
188-
"source": [
189-
"1/2"
190-
]
191-
},
192-
{
193-
"cell_type": "code",
194-
"execution_count": 16,
195-
"metadata": {
196-
"vscode": {
197-
"languageId": "c++"
198-
}
199-
},
200-
"outputs": [
201-
{
202-
"data": {
203-
"text/plain": [
204-
"50.000000"
205-
]
206-
},
207-
"execution_count": 16,
208-
"metadata": {},
209-
"output_type": "execute_result"
210-
}
211-
],
212-
"source": [
213-
"0.5 * 100"
86+
"significand_d = std::round(significand_d * (1ll << 31));"
21487
]
21588
},
21689
{

Diff for: doc/exercises/sigmod.cc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
double x = 2.302585093;
2+
double y;
3+
4+
y = exp(x);
5+
6+
double sigmoid(double x) {
7+
return 1/(1+exp(-x));
8+
}
9+
10+
sigmoid(1)

Diff for: doc/wiki/ifndef.ipynb

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
{
1515
"cell_type": "code",
1616
"execution_count": 1,
17-
"metadata": {},
17+
"metadata": {
18+
"vscode": {
19+
"languageId": "c++"
20+
}
21+
},
1822
"outputs": [],
1923
"source": [
2024
"#ifndef HEADER_H\n",
@@ -45,7 +49,7 @@
4549
"codemirror_mode": "text/x-c++src",
4650
"file_extension": ".cpp",
4751
"mimetype": "text/x-c++src",
48-
"name": "c++",
52+
"name": "C++14",
4953
"version": "14"
5054
}
5155
},

0 commit comments

Comments
 (0)