2
2
* Correctly rounded expm1 = e^x - 1
3
3
*
4
4
* Author : Christoph Lauter (ENS Lyon)
5
+ * One bug fix by Florent de Dinechin
5
6
*
6
7
* This file is part of the crlibm library developed by the Arenaire
7
8
* project at Ecole Normale Superieure de Lyon
@@ -230,7 +231,7 @@ void expm1_common_td(double *expm1h, double *expm1m, double *expm1l,
230
231
expm = polyWithTablesmdb .d ;
231
232
expl = polyWithTablesldb .d ;
232
233
233
- /* Substraction of -1
234
+ /* Subtraction of -1
234
235
235
236
We use a conditional Add133
236
237
*/
@@ -245,7 +246,7 @@ void expm1_common_td(double *expm1h, double *expm1m, double *expm1l,
245
246
246
247
247
248
double expm1_rn (double x ) {
248
- db_number xdb , shiftedXMultdb , twoToM ;
249
+ db_number xdb , shiftedXMultdb , polyTblhdb , polyTblmdb ;
249
250
int xIntHi , expoX , k , M , index1 , index2 ;
250
251
double highPoly , tt1h , t1h , t1l , xSqh , xSql , xSqHalfh , xSqHalfl , xCubeh , xCubel , t2h , t2l , templ , tt3h , tt3l ;
251
252
double polyh , polyl , expm1h , expm1m , expm1l ;
@@ -499,36 +500,23 @@ double expm1_rn(double x) {
499
500
500
501
Add12 (t11 ,t12 ,tablesh ,t10 );
501
502
t13 = t12 + tablesl ;
502
- Add12 (exph , expm , t11 ,t13 );
503
+ Add12 (polyTblhdb . d , polyTblmdb . d , t11 ,t13 );
503
504
504
505
/* Reconstruction: multiplication by 2^M */
505
506
507
+ /* Implement the multiplication by addition to overcome the
508
+ problem of the non-representability of 2^1024 (M = 1024)
509
+ This case is possible if polyTblhdb.d < 1
510
+ */
506
511
507
- /* Bug found by Morten Welinder, tanks to him:
508
- The multiplication was implemented as
509
-
510
- polyTblhdb.i[HI] += M << 20;
512
+ polyTblhdb .i [HI ] += M << 20 ;
513
+ if (polyTblmdb .d != 0.0 ) /* predicted true, but it happens for x=-4.1588039009762204, thanks Morten */
511
514
polyTblmdb .i [HI ] += M << 20 ;
512
515
513
- (where polyTblh/l were dbnumber versions of exph and expm)
514
-
515
- polyTblh is under control, but he found one case where polyTblm is zero
516
- (for x=-4.1588039009762204 and a few neighbouring values)
517
- In this case M=-6, and adding -6 to the 0 exponent gives a very large value.
518
-
519
- Anyway the version fixed here is barely slower.
520
-
521
- */
522
-
523
- /* build 2^M -- let's hope the compiler schedules it early enough */
524
-
525
- twoToM .i [HI ] = 0x3FF00000 + (M << 20 );
526
- twoToM .i [LO ] = 0 ;
527
-
528
- exph *= twoToM .d ;
529
- expm *= twoToM .d ;
516
+ exph = polyTblhdb .d ;
517
+ expm = polyTblmdb .d ;
530
518
531
- /* Substraction of 1
519
+ /* Subtraction of 1
532
520
533
521
Testing if the operation is necessary is more expensive than
534
522
performing it in any case.
@@ -537,7 +525,7 @@ double expm1_rn(double x) {
537
525
arguments 1/4 <= x <= ln(2) (0.25 <= x <= 0.69)
538
526
We must therefore use conditional Add12s
539
527
540
- Since we perform a substraction , we may not have addition overflow towards +inf
528
+ Since we perform a subtraction , we may not have addition overflow towards +inf
541
529
542
530
*/
543
531
@@ -836,18 +824,19 @@ double expm1_rd(double x) {
836
824
837
825
/* Reconstruction: multiplication by 2^M */
838
826
839
- /* Implement the multiplication by multiplication to overcome the
827
+ /* Implement the multiplication by addition to overcome the
840
828
problem of the non-representability of 2^1024 (M = 1024)
841
829
This case is possible if polyTblhdb.d < 1
842
830
*/
843
831
844
832
polyTblhdb .i [HI ] += M << 20 ;
845
- polyTblmdb .i [HI ] += M << 20 ;
833
+ if (polyTblmdb .d != 0.0 ) /* predicted true, but it happens for x=-4.1588039009762204, thanks Morten */
834
+ polyTblmdb .i [HI ] += M << 20 ;
846
835
847
836
exph = polyTblhdb .d ;
848
837
expm = polyTblmdb .d ;
849
838
850
- /* Substraction of 1
839
+ /* Subtraction of 1
851
840
852
841
Testing if the operation is necessary is more expensive than
853
842
performing it in any case.
@@ -856,7 +845,7 @@ double expm1_rd(double x) {
856
845
arguments 1/4 <= x <= ln(2) (0.25 <= x <= 0.69)
857
846
We must therefore use conditional Add12s
858
847
859
- Since we perform a substraction , we may not have addition overflow towards +inf
848
+ Since we perform a subtraction , we may not have addition overflow towards +inf
860
849
861
850
*/
862
851
@@ -1160,18 +1149,19 @@ double expm1_ru(double x) {
1160
1149
1161
1150
/* Reconstruction: multiplication by 2^M */
1162
1151
1163
- /* Implement the multiplication by multiplication to overcome the
1152
+ /* Implement the multiplication by addition to overcome the
1164
1153
problem of the non-representability of 2^1024 (M = 1024)
1165
1154
This case is possible if polyTblhdb.d < 1
1166
1155
*/
1167
1156
1168
1157
polyTblhdb .i [HI ] += M << 20 ;
1169
- polyTblmdb .i [HI ] += M << 20 ;
1158
+ if (polyTblmdb .d != 0.0 ) /* predicted true, but it happens for x=-4.1588039009762204, thanks Morten */
1159
+ polyTblmdb .i [HI ] += M << 20 ;
1170
1160
1171
1161
exph = polyTblhdb .d ;
1172
1162
expm = polyTblmdb .d ;
1173
1163
1174
- /* Substraction of 1
1164
+ /* Subtraction of 1
1175
1165
1176
1166
Testing if the operation is necessary is more expensive than
1177
1167
performing it in any case.
@@ -1180,7 +1170,7 @@ double expm1_ru(double x) {
1180
1170
arguments 1/4 <= x <= ln(2) (0.25 <= x <= 0.69)
1181
1171
We must therefore use conditional Add12s
1182
1172
1183
- Since we perform a substraction , we may not have addition overflow towards +inf
1173
+ Since we perform a subtraction , we may not have addition overflow towards +inf
1184
1174
1185
1175
*/
1186
1176
@@ -1492,18 +1482,19 @@ double expm1_rz(double x) {
1492
1482
1493
1483
/* Reconstruction: multiplication by 2^M */
1494
1484
1495
- /* Implement the multiplication by multiplication to overcome the
1485
+ /* Implement the multiplication by addition to overcome the
1496
1486
problem of the non-representability of 2^1024 (M = 1024)
1497
1487
This case is possible if polyTblhdb.d < 1
1498
1488
*/
1499
1489
1500
- polyTblhdb .i [HI ] += M << 20 ;
1501
- polyTblmdb .i [HI ] += M << 20 ;
1490
+ polyTblhdb .i [HI ] += M << 20 ;
1491
+ if (polyTblmdb .d != 0.0 ) /* predicted true, but it happens for x=-4.1588039009762204, thanks Morten */
1492
+ polyTblmdb .i [HI ] += M << 20 ;
1502
1493
1503
1494
exph = polyTblhdb .d ;
1504
1495
expm = polyTblmdb .d ;
1505
1496
1506
- /* Substraction of 1
1497
+ /* Subtraction of 1
1507
1498
1508
1499
Testing if the operation is necessary is more expensive than
1509
1500
performing it in any case.
@@ -1512,7 +1503,7 @@ double expm1_rz(double x) {
1512
1503
arguments 1/4 <= x <= ln(2) (0.25 <= x <= 0.69)
1513
1504
We must therefore use conditional Add12s
1514
1505
1515
- Since we perform a substraction , we may not have addition overflow towards +inf
1506
+ Since we perform a subtraction , we may not have addition overflow towards +inf
1516
1507
1517
1508
*/
1518
1509
@@ -2207,22 +2198,24 @@ interval j_expm1(interval x)
2207
2198
2208
2199
/* Reconstruction: multiplication by 2^M */
2209
2200
2210
- /* Implement the multiplication by multiplication to overcome the
2201
+ /* Implement the multiplication by addition to overcome the
2211
2202
problem of the non-representability of 2^1024 (M = 1024)
2212
2203
This case is possible if polyTblhdb.d < 1
2213
2204
*/
2214
2205
2215
2206
polyTblhdb_inf .i [HI ] += M_inf << 20 ;
2216
2207
polyTblhdb_sup .i [HI ] += M_sup << 20 ;
2217
- polyTblmdb_inf .i [HI ] += M_inf << 20 ;
2218
- polyTblmdb_sup .i [HI ] += M_sup << 20 ;
2208
+ if (polyTblmdb_inf .d != 0.0 ) /* predicted true, but it happens for x=-4.1588039009762204, thanks Morten */
2209
+ polyTblmdb_inf .i [HI ] += M_inf << 20 ;
2210
+ if (polyTblmdb_sup .d != 0.0 ) /* predicted true, but it happens for x=-4.1588039009762204, thanks Morten */
2211
+ polyTblmdb_sup .i [HI ] += M_sup << 20 ;
2219
2212
2220
2213
exph_inf = polyTblhdb_inf .d ;
2221
2214
exph_sup = polyTblhdb_sup .d ;
2222
2215
expm_inf = polyTblmdb_inf .d ;
2223
2216
expm_sup = polyTblmdb_sup .d ;
2224
2217
2225
- /* Substraction of 1
2218
+ /* Subtraction of 1
2226
2219
2227
2220
Testing if the operation is necessary is more expensive than
2228
2221
performing it in any case.
@@ -2231,7 +2224,7 @@ interval j_expm1(interval x)
2231
2224
arguments 1/4 <= x <= ln(2) (0.25 <= x <= 0.69)
2232
2225
We must therefore use conditional Add12s
2233
2226
2234
- Since we perform a substraction , we may not have addition overflow towards +inf
2227
+ Since we perform a subtraction , we may not have addition overflow towards +inf
2235
2228
2236
2229
*/
2237
2230
@@ -2348,18 +2341,19 @@ interval j_expm1(interval x)
2348
2341
2349
2342
/* Reconstruction: multiplication by 2^M */
2350
2343
2351
- /* Implement the multiplication by multiplication to overcome the
2344
+ /* Implement the multiplication by addition to overcome the
2352
2345
problem of the non-representability of 2^1024 (M = 1024)
2353
2346
This case is possible if polyTblhdb.d < 1
2354
2347
*/
2355
2348
2356
2349
polyTblhdb_inf .i [HI ] += M_inf << 20 ;
2357
- polyTblmdb_inf .i [HI ] += M_inf << 20 ;
2350
+ if (polyTblmdb_inf .d != 0.0 ) /* predicted true, but it happens for x=-4.1588039009762204, thanks Morten */
2351
+ polyTblmdb_inf .i [HI ] += M_inf << 20 ;
2358
2352
2359
2353
exph_inf = polyTblhdb_inf .d ;
2360
2354
expm_inf = polyTblmdb_inf .d ;
2361
2355
2362
- /* Substraction of 1
2356
+ /* Subtraction of 1
2363
2357
2364
2358
Testing if the operation is necessary is more expensive than
2365
2359
performing it in any case.
@@ -2368,7 +2362,7 @@ interval j_expm1(interval x)
2368
2362
arguments 1/4 <= x <= ln(2) (0.25 <= x <= 0.69)
2369
2363
We must therefore use conditional Add12s
2370
2364
2371
- Since we perform a substraction , we may not have addition overflow towards +inf
2365
+ Since we perform a subtraction , we may not have addition overflow towards +inf
2372
2366
2373
2367
*/
2374
2368
@@ -2460,18 +2454,19 @@ interval j_expm1(interval x)
2460
2454
2461
2455
/* Reconstruction: multiplication by 2^M */
2462
2456
2463
- /* Implement the multiplication by multiplication to overcome the
2457
+ /* Implement the multiplication by addition to overcome the
2464
2458
problem of the non-representability of 2^1024 (M = 1024)
2465
2459
This case is possible if polyTblhdb.d < 1
2466
2460
*/
2467
2461
2468
2462
polyTblhdb_sup .i [HI ] += M_sup << 20 ;
2469
- polyTblmdb_sup .i [HI ] += M_sup << 20 ;
2463
+ if (polyTblmdb_sup .d != 0.0 ) /* predicted true, but it happens for x=-4.1588039009762204, thanks Morten */
2464
+ polyTblmdb_sup .i [HI ] += M_sup << 20 ;
2470
2465
2471
2466
exph_sup = polyTblhdb_sup .d ;
2472
2467
expm_sup = polyTblmdb_sup .d ;
2473
2468
2474
- /* Substraction of 1
2469
+ /* Subtraction of 1
2475
2470
2476
2471
Testing if the operation is necessary is more expensive than
2477
2472
performing it in any case.
@@ -2480,7 +2475,7 @@ interval j_expm1(interval x)
2480
2475
arguments 1/4 <= x <= ln(2) (0.25 <= x <= 0.69)
2481
2476
We must therefore use conditional Add12s
2482
2477
2483
- Since we perform a substraction , we may not have addition overflow towards +inf
2478
+ Since we perform a subtraction , we may not have addition overflow towards +inf
2484
2479
2485
2480
*/
2486
2481
0 commit comments