help-octave
[Top][All Lists]
Advanced

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

Re: Same .m file: different results with different versions of Octave


From: Thomas D. Dean
Subject: Re: Same .m file: different results with different versions of Octave
Date: Wed, 21 Apr 2010 05:43:17 -0700

On Wed, 2010-04-21 at 05:19 -0700, Thomas D. Dean wrote:

Sorry, I should have posted complete code.
Are we over-thinking this?
What is wrong with:

#include <iostream>
#include <complex>
#include <gnu/libc-version.h>
#include <stdlib.h> // atol

using namespace std;

#define CTYPE long double

int main(int argc, char **argv) {
  long mult;
  if (argc == 2) {
        mult = atol(argv[1]);
  } else {
        mult = 50000L;
  }
  complex<CTYPE> arg(1,1);

  arg *= (CTYPE)mult;

  complex<CTYPE> s,c,r,t;

  s=sinh(arg);
  c=cosh(arg);
  r=s/c;
  // arg=complex<CTYPE>(nan(""),1); // or inf or something
  // if arg is not finite, do something...
  if ( !isfinite(arg.real()) || !isfinite(arg.imag()) ) {
        t=complex<CTYPE>(nan(""),nan(""));
  } else if ( isfinite(s.real()) && isfinite(s.imag())
           && isfinite(c.real()) && isfinite(c.imag()) ) {
        // The min value of cosh() is 1
        t = sinh(arg)/cosh(arg);
  } else {
        // overflow
        t=complex<CTYPE>(1,0);
  }
  
  cout << "libc version " << gnu_get_libc_version() << endl;
  cout << "libc release " << gnu_get_libc_release() << endl;
  cout << "sizeof arg   " << sizeof(CTYPE) << " Bytes" << endl;
  cout << "arg       " << arg << endl;
  cout << "sinh(arg) " << s << endl;
  cout << "cosh(arg) " << c << endl;
  cout << "s/c       " << r << endl;
  cout << "tanh(arg) " << t << endl;

  return 0;
}




reply via email to

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