octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #49091] MinGW std::acosh less accurate than Li


From: Markus Mützel
Subject: [Octave-bug-tracker] [bug #49091] MinGW std::acosh less accurate than Linux versions
Date: Thu, 4 Aug 2022 13:17:02 -0400 (EDT)

Follow-up Comment #20, bug #49091 (project octave):

I tested with the following compiled to an .oct file:

#include <iostream>
#include <cmath>
#include <complex>

#include <octave/oct.h>
#include <octave/lo-specfun.h>

DEFUN_DLD(test_acosh_oct, args, nargout,
          "-*- texinfo -*-\n\
@deftypefn {} {@var{retval} =} test_acosh_oct (@var{input1}, @var{input2})\n\
@seealso{}\n\
@end deftypefn")
{
//  octave_value_list retval;
  int nargin = args.length ();
  double x = 0;
  double y = 10;
  std::cout.precision(17);
  std::cout << "x = " << x << std::endl;
  std::cout << "y = " << y << std::endl;

  // libstdc++
  std::complex<double> zcpp (x, y);
  std::complex<double> retcpp = std::acosh (zcpp);
  std::cout << "std::acosh(x+1i*y) = " << retcpp.real () << " + " <<
retcpp.imag () << "i" << std::endl;

  zcpp.imag (-y);
  retcpp = std::acosh (zcpp);
  std::cout << "std::acosh(x-1i*y) = " << retcpp.real () << " + " <<
retcpp.imag () << "i" << std::endl;

  // liboctave
  Complex zoct_p (x, y);
  Complex retoct_p = octave::math::acosh (zoct_p);
  Complex zoct_m (x, -y);
  Complex retoct_m = octave::math::acosh (zoct_m);

  // liboctinterp
  octave_value zoctint_p (zoct_p);
  octave_value zoctint_m (zoct_m);

  return ovl (retoct_p, retoct_m, zoctint_p.acosh (), zoctint_m.acosh ());
}


Executing it in Octave 7.2.0 yields:

>> mkoctfile test_acosh_oct.cc
>> [p, m] = test_acosh_oct;
x = 0
y = 10
std::acosh(x+1i*y) = 2.9982229502979698 + 1.5707963267948966i
std::acosh(x-1i*y) = 2.9982229502979698 + -1.5707963267948966i
>> [p, m, pi, mi] = test_acosh_oct;
x = 0
y = 10
std::acosh(x+1i*y) = 2.9982229502979698 + 1.5707963267948966i
std::acosh(x-1i*y) = 2.9982229502979698 + -1.5707963267948966i
>> fprintf ('acosh(x+iy) = %.16f + %.16fi\n', real (p), imag (p));
acosh(x+iy) = 2.9982229502979698 + 1.5707963267948966i
>> fprintf ('acosh(x-iy) = %.16f + %.16fi\n', real (m), imag (m));
acosh(x-iy) = 2.9982229502979698 + -1.5707963267948966i
>> fprintf ('acosh(x+iy) = %.16f + %.16fi\n', real (pi), imag (pi));
acosh(x+iy) = 2.9982229502979698 + 1.5707963267948966i
>> fprintf ('acosh(x-iy) = %.16f + %.16fi\n', real (mi), imag (mi));
acosh(x-iy) = 2.9982229502979698 + -1.5707963267948966i
>> z = acosh (10i);
>> printf ("Octave acosh(10i)  = %.16f + %.16fi\n", real (z), imag (z));
Octave acosh(10i)  = 2.9982229502979698 + 1.5707963267948966i
>> z = acosh (-10i);
>> printf ("Octave acosh(-10i) = %.16f + %.16fi\n", real (z), imag (z));
Octave acosh(-10i) = 2.9982229502979760 + -1.5707963267948966i


All results but for the last command look good to me.
I don't know what is going on here...

Is the parser doing something strange when it comes across `-10i`? 😖
The following result is fine:

>> z = acosh (complex(0,-10));
>> printf ("Octave acosh(-10i) = %.16f + %.16fi\n", real (z), imag (z));
Octave acosh(-10i) = 2.9982229502979698 + -1.5707963267948966i


Why only on Windows???



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?49091>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]