Skip to content

Commit 5ef1fe2

Browse files
committed
add Math::c{log,acos,asin,acosh,atanh} - fix #527
1 parent 4719490 commit 5ef1fe2

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- add do_print to perldl to match pdl2
3030
- add {which,where}ND_both - thanks @guillepo for inspiration
3131
- add Core::tocomplex (#527) - thanks @wlmb for suggestion
32+
- add Math::c{log,acos,asin,acosh,atanh} (#527) - thanks @wlmb for suggestion
3233

3334
2.098 2025-01-03
3435
- fix Windows build problems

lib/PDL/Math.pd

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -489,20 +489,25 @@ works with native-complex data.
489489
($yr, $yi) = polyval($cr, $ci, $xr, $xi);
490490
',);
491491

492-
pp_def('csqrt',
493-
GenericTypes => $AF,
494-
Pars => 'i(); complex [o] o()',
495-
Doc => <<'EOF',
496-
Take the complex square root of a number choosing that with
497-
non-negative real part, i.e., a square root with a branch cut
498-
'infinitesimally' below the negative real axis, the standard choice.
492+
sub cequiv {
493+
my ($func, $ref) = @_;
494+
pp_def("c$func",
495+
GenericTypes => $AF,
496+
Pars => 'i(); complex [o] o()',
497+
Doc => <<EOF,
498+
=for ref\n
499+
Takes real or complex data, returns the complex C<$func>.\n
500+
Added in 2.099.
499501
EOF
500-
Code => q{
501-
$TFDEGCH(PDL_CFloat,PDL_CDouble,PDL_CLDouble,PDL_CFloat,PDL_CDouble,PDL_CLDouble) tmp=$i();
502-
tmp=csqrt(tmp);
503-
$o() = tmp;
504-
},
505-
);
502+
Code => pp_line_numbers(__LINE__, <<EOF),
503+
\$TFDEGCH(PDL_CFloat,PDL_CDouble,PDL_CLDouble,PDL_CFloat,PDL_CDouble,PDL_CLDouble) tmp = \$i();
504+
tmp = c$func(tmp);
505+
\$o() = tmp;
506+
EOF
507+
);
508+
}
509+
510+
cequiv($_) for qw(sqrt log acos asin acosh atanh);
506511

507512
pp_def('csqrt_up',
508513
GenericTypes => $AF,
@@ -512,23 +517,16 @@ Take the complex square root of a number choosing that whose imaginary
512517
part is not negative, i.e., it is a square root with a branch cut
513518
'infinitesimally' below the positive real axis.
514519
EOF
515-
Code => q{
516-
$TFDEGCH(PDL_CFloat,PDL_CDouble,PDL_CLDouble,PDL_CFloat,PDL_CDouble,PDL_CLDouble) tmp=$i();
517-
tmp=csqrt(tmp);
518-
if(cimag(tmp)<0){
519-
tmp = -tmp;
520-
}
521-
$o() = tmp;
522-
},
520+
Code => pp_line_numbers(__LINE__, <<'EOF'),
521+
$TFDEGCH(PDL_CFloat,PDL_CDouble,PDL_CLDouble,PDL_CFloat,PDL_CDouble,PDL_CLDouble) tmp = $i();
522+
tmp = csqrt(tmp);
523+
if (cimag(tmp)<0)
524+
tmp = -tmp;
525+
$o() = tmp;
526+
EOF
523527
);
524528

525529
pp_addpm({At=>'Bot'},<<'EOD');
526-
527-
=head1 BUGS
528-
529-
Hasn't been tested on all platforms to ensure Cephes
530-
versions are picked up automatically and used correctly.
531-
532530
=head1 AUTHOR
533531

534532
Copyright (C) R.J.R. Williams 1997 (rjrw@ast.leeds.ac.uk), Karl Glazebrook

t/math.t

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ is_pdl erfi(erf(0.5)), pdl(0.5), "erfi (both ways)";
5454
is_pdl pdl('-2i')->csqrt, pdl('1-i');
5555
}
5656

57+
is_pdl cacosh(-1), pdl('3.141592i');
58+
is_pdl clog(-1), pdl('3.141592i');
59+
is_pdl cacos(-2), pdl('3.141592-1.316957i');
60+
is_pdl casin(-2), pdl('-1.570796+1.316957i');
61+
is_pdl tanh(catanh(-2)), cdouble(-2); # Cygwin catanh returns with negative Im
62+
5763
{ # csqrt_up
5864
my $pi=4*atan2(1,1);
5965
my $eiO = exp(i()*sequence(8)*$pi/4);

0 commit comments

Comments
 (0)