Skip to content

Commit

Permalink
Use $TFDEGCH in csqrt routines. Rename _csqrt_right to csqrt
Browse files Browse the repository at this point in the history
  • Loading branch information
wlmb committed Jan 15, 2025
1 parent 768055a commit 60a4ae6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
10 changes: 5 additions & 5 deletions lib/PDL/Ops.pd
Original file line number Diff line number Diff line change
Expand Up @@ -422,16 +422,16 @@ EOF
Code => '$c() = $r() + $i() * I;'
);

pp_def('csqrt_right',
pp_def('csqrt',
GenericTypes => $AF,
Pars => 'i(); complex [o] o()',
Doc => <<'EOF',
Take the complex square root of a number choosing that with
not negative real part, i.e., a square root with a branch cut
'infinitesimally' below the negative real axis.
non-negative real part, i.e., a square root with a branch cut
'infinitesimally' below the negative real axis, the standard choice.
EOF
Code => q{
PDL_IF_GENTYPE_REAL(complex,$GENERIC()) tmp=$i();
$TFDEGCH(PDL_CFloat,PDL_CDouble,PDL_CLDouble,PDL_CFloat,PDL_CDouble,PDL_CLDouble) tmp=$i();
tmp=csqrt(tmp);
$o() = tmp;
},
Expand All @@ -446,7 +446,7 @@ part is not negative, i.e., it is a square root with a branch cut
'infinitesimally' below the positive real axis.
EOF
Code => q{
PDL_IF_GENTYPE_REAL(complex,$GENERIC()) tmp=$i();
$TFDEGCH(PDL_CFloat,PDL_CDouble,PDL_CLDouble,PDL_CFloat,PDL_CDouble,PDL_CLDouble) tmp=$i();
tmp=csqrt(tmp);
if(cimag(tmp)<0){
tmp = -tmp;
Expand Down
42 changes: 21 additions & 21 deletions t/ops.t
Original file line number Diff line number Diff line change
Expand Up @@ -112,32 +112,32 @@ if ($can_complex_power) {
is $pa->at(0), '16', 'sqrt orig value ok';
}

{ # csqrt_right
{ # csqrt
my $pi=4*atan2(1,1);
my $eiO = exp(i()*(sequence(8)-3)*$pi/4);
my $eiO2 = exp(i()*(sequence(8)-3)*$pi/8);
my $sqrt=csqrt_right($eiO);
is_pdl($sqrt, $eiO2, "csqrt_right of complex");
my $i=csqrt_right(-1);
is_pdl($i, i(), "csqrt_right of real -1");
my $sqrt=csqrt($eiO);
is_pdl($sqrt, $eiO2, "csqrt of complex");
my $i=csqrt(-1);
is_pdl($i, i(), "csqrt of real -1");
my $squares="-9 -4 -1 0 1 4 9";
my $roots="3i 2i i 0 1 2 3";
my $lsqrt=long($squares)->csqrt_right;
is_pdl($lsqrt, cdouble($roots), "csqrt_right of long");
my $llsqrt=longlong($squares)->csqrt_right;
is_pdl($llsqrt, cdouble($roots), "csqrt_right of longlong");
my $fsqrt=float($squares)->csqrt_right;
is_pdl($fsqrt, cfloat($roots), "csqrt_right of float");
my $dsqrt=double($squares)->csqrt_right;
is_pdl($dsqrt,cdouble($roots), "csqrt_right of double");
my $ldsqrt=ldouble($squares)->csqrt_right;
is_pdl($ldsqrt, cldouble($roots), "csqrt_right of ldouble");
my $cfsqrt=cfloat($squares)->csqrt_right;
is_pdl($cfsqrt, cfloat($roots), "csqrt_right of cfloat");
my $cdsqrt=cdouble($squares)->csqrt_right;
is_pdl($cdsqrt,cdouble($roots), "csqrt_right of cdouble");
my $cldsqrt=cldouble($squares)->csqrt_right;
is_pdl($cldsqrt,cldouble($roots), "csqrt_right of cldouble");
my $lsqrt=long($squares)->csqrt;
is_pdl($lsqrt, cdouble($roots), "csqrt of long");
my $llsqrt=longlong($squares)->csqrt;
is_pdl($llsqrt, cdouble($roots), "csqrt of longlong");
my $fsqrt=float($squares)->csqrt;
is_pdl($fsqrt, cfloat($roots), "csqrt of float");
my $dsqrt=double($squares)->csqrt;
is_pdl($dsqrt,cdouble($roots), "csqrt of double");
my $ldsqrt=ldouble($squares)->csqrt;
is_pdl($ldsqrt, cldouble($roots), "csqrt of ldouble");
my $cfsqrt=cfloat($squares)->csqrt;
is_pdl($cfsqrt, cfloat($roots), "csqrt of cfloat");
my $cdsqrt=cdouble($squares)->csqrt;
is_pdl($cdsqrt,cdouble($roots), "csqrt of cdouble");
my $cldsqrt=cldouble($squares)->csqrt;
is_pdl($cldsqrt,cldouble($roots), "csqrt of cldouble");
}

{ # csqrt_up
Expand Down

0 comments on commit 60a4ae6

Please sign in to comment.