Skip to content

Commit a3c9e53

Browse files
duncanitac3d
authored andcommitted
complex: Fix expm1 formula computing exp(z-1) instead of exp(z)-1
The complex implementation of expm1(z) incorrectly computed e^(z-1) instead of e^z - 1. Added tests for complex expm1 to prevent regression.
1 parent 57dcd27 commit a3c9e53

File tree

6 files changed

+18
-1
lines changed

6 files changed

+18
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This software was brought to you by the DB48X authors below
1616
- Ed van Gasteren <Ed@vanGasteren.net> (Bug fixes)
1717
- Jerome Ibanes <jibanes@gmail.com> (Dockerfile)
1818
- Jesus Cano <jcanovel@gmail.com>
19+
- Riccardo Lucatuorto <gnuduncan@gmail.com>
1920

2021
Copyright (c) 2022-2025, the DB48X authors
2122

doc/0-Overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ Additional contributors to the project include (in order of appearance):
825825
* Ed van Gasteren (Ed@vanGasteren.net) (Bug fixes)
826826
* Jerome Ibanes (jibanes@gmail.com) (Dockerfile)
827827
* Jesus Cano (jcanovel@gmail.com) (bug fixes)
828+
* Riccardo Lucatuorto (gnuduncan@gmail.com)
828829

829830
The authors would like to acknowledge
830831

help/db48x.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ Additional contributors to the project include (in order of appearance):
767767
* Ed van Gasteren (Ed@vanGasteren.net) (Bug fixes)
768768
* Jerome Ibanes (jibanes@gmail.com) (Dockerfile)
769769
* Jesus Cano (jcanovel@gmail.com) (bug fixes)
770+
* Riccardo Lucatuorto (gnuduncan@gmail.com)
770771

771772
The authors would like to acknowledge
772773

help/db50x.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ Additional contributors to the project include (in order of appearance):
776776
* Ed van Gasteren (Ed@vanGasteren.net) (Bug fixes)
777777
* Jerome Ibanes (jibanes@gmail.com) (Dockerfile)
778778
* Jesus Cano (jcanovel@gmail.com) (bug fixes)
779+
* Riccardo Lucatuorto (gnuduncan@gmail.com)
779780

780781
The authors would like to acknowledge
781782

src/complex.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,13 +1266,14 @@ COMPLEX_BODY(ln1p)
12661266
return ln(one + z);
12671267
}
12681268

1269+
12691270
COMPLEX_BODY(expm1)
12701271
// ----------------------------------------------------------------------------
12711272
// Complex implementation of expm1
12721273
// ----------------------------------------------------------------------------
12731274
{
12741275
complex_g one = complex::make(1, 0);
1275-
return exp(z - one);
1276+
return exp(z) - one;
12761277
}
12771278

12781279

src/tests.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5101,6 +5101,18 @@ void tests::complex_functions()
51015101
test(ID_exp)
51025102
.expect("18.43908 89145 85774 62∡0.86217 00546 67226 34884ʳ");
51035103

5104+
step("Complex exponential minus 1 (zero)");
5105+
test(CLEAR, "0+0ⅈ expm1", ENTER)
5106+
.expect("0+0ⅈ"); // expm1(0) = e^0 - 1 = 0
5107+
5108+
step("Complex exponential minus 1 (real)");
5109+
test(CLEAR, "1+0ⅈ expm1", ENTER)
5110+
.match("1\\.71828.*\\+0ⅈ"); // e - 1
5111+
5112+
step("Complex exponential minus 1 (imaginary)");
5113+
test(CLEAR, "0+3.14159265358979323846ⅈ expm1", ENTER)
5114+
.match("-2\\..*ⅈ"); // expm1(πi) ≈ -2 (with tiny floating point error)
5115+
51045116
step("Power");
51055117
test(CLEAR, "3+7ⅈ", ENTER, "2-3ⅈ", ID_pow)
51065118
.expect("1 916.30979 15541 96293 8∡2.52432 98723 79583 8639ʳ");

0 commit comments

Comments
 (0)