File tree 3 files changed +21
-134
lines changed
3 files changed +21
-134
lines changed Original file line number Diff line number Diff line change 25
25
" - `x`:浮点值。\n " ,
26
26
" - `expptr`:指向存储的整数指数的指针。\n " ,
27
27
" \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 " ,
29
29
" \n " ,
30
30
" ```{note}\n " ,
31
31
" `frexp` 函数将浮点值(`x`)分解为尾数(mantissa `m`)和指数(exponent,`n`),使绝对值 `m` 大于或等于 `0.5` 且小于 `1.0`,并且 $x = m * 2^n$。整数指数 `n` 存储在由 `expptr` 指向的位置。\n " ,
63
63
]
64
64
},
65
65
{
66
- "cell_type" : " code" ,
67
- "execution_count" : 7 ,
66
+ "cell_type" : " markdown" ,
68
67
"metadata" : {
69
68
"vscode" : {
70
69
"languageId" : " c++"
71
70
}
72
71
},
73
- "outputs" : [],
74
72
"source" : [
75
- " double x = 2.302585093;\n " ,
76
- " double y;\n " ,
77
- " \n " ,
78
- " y = exp(x);"
73
+ " 将双精度有效数字转换为整数有效数字,即将小数点放在第 31 位和第 30 位之间。这是通过将双精度值乘以 $2^{31}$,然后将其转换为 int 来实现的。"
79
74
]
80
75
},
81
76
{
82
77
"cell_type" : " code" ,
83
- "execution_count" : 10 ,
78
+ "execution_count" : 3 ,
84
79
"metadata" : {
85
80
"vscode" : {
86
81
"languageId" : " c++"
87
82
}
88
83
},
89
84
"outputs" : [],
90
85
"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));"
214
87
]
215
88
},
216
89
{
Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change 14
14
{
15
15
"cell_type" : " code" ,
16
16
"execution_count" : 1 ,
17
- "metadata" : {},
17
+ "metadata" : {
18
+ "vscode" : {
19
+ "languageId" : " c++"
20
+ }
21
+ },
18
22
"outputs" : [],
19
23
"source" : [
20
24
" #ifndef HEADER_H\n " ,
45
49
"codemirror_mode" : " text/x-c++src" ,
46
50
"file_extension" : " .cpp" ,
47
51
"mimetype" : " text/x-c++src" ,
48
- "name" : " c++ " ,
52
+ "name" : " C++14 " ,
49
53
"version" : " 14"
50
54
}
51
55
},
You can’t perform that action at this time.
0 commit comments