Mercurial > hg > octave-nkf
changeset 19935:554aaaf99644
Fix return phase of acosh to match Matlab (bug #44286).
* NEWS: Announce change.
* mappers.cc (Facosh): Add BIST tests for new behavior.
* lo-mappers.cc: Re-write expression sqrt (x*x -1.0) as
sqrt (x + 1.0) * sqrt (x - 1.0) which gets phase correct if x is complex.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 17 Feb 2015 11:07:01 -0800 |
parents | 17a7e9f26e50 |
children | 9861618b4c5f |
files | NEWS libinterp/corefcn/mappers.cc liboctave/numeric/lo-mappers.cc |
diffstat | 3 files changed, 18 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS +++ b/NEWS @@ -87,6 +87,10 @@ limit from above is taken. This criteria is consistent with several other numerical analysis software packages. + ** The hyperbolic function acosh now returns values with a phase in the range + [-pi/2, +pi/2]. Previously Octave returned values in the range [0, pi]. + This is consistent with several other numerical analysis software packages. + ** strfind changes when using empty pattern ("") for Matlab compatibility strfind now returns an empty array when the pattern itself is empty.
--- a/libinterp/corefcn/mappers.cc +++ b/libinterp/corefcn/mappers.cc @@ -155,10 +155,22 @@ %! assert (acosh (x), v, sqrt (eps)); %!test +%! re = 2.99822295029797; +%! im = pi/2; +%! assert (acosh (10i), re + i*im); +%! assert (acosh (-10i), re - i*im); + +%!test %! x = single ([1, 0, -1, 0]); %! v = single ([0, pi/2*i, pi*i, pi/2*i]); %! assert (acosh (x), v, sqrt (eps ("single"))); +%!test +%! re = single (2.99822295029797); +%! im = single (pi/2); +%! assert (acosh (single (10i)), re + i*im, 5*eps ("single")); +%! assert (acosh (single (-10i)), re - i*im, 5*eps ("single")); + %!error acosh () %!error acosh (1, 2) */
--- a/liboctave/numeric/lo-mappers.cc +++ b/liboctave/numeric/lo-mappers.cc @@ -197,7 +197,7 @@ Complex acosh (const Complex& x) { - return log (x + sqrt (x*x - 1.0)); + return log (x + sqrt (x + 1.0) * sqrt (x - 1.0)); } Complex @@ -434,7 +434,7 @@ FloatComplex acosh (const FloatComplex& x) { - return log (x + sqrt (x*x - static_cast<float>(1.0))); + return log (x + sqrt (x + 1.0f) * sqrt (x - 1.0f)); } FloatComplex