Project

General

Profile

Bug #5497

Math.log10(10_000) error on HP-UX/PA

Added by twwlogin (The Written Word Inc) almost 6 years ago. Updated 3 months ago.

Status:
Feedback
Priority:
Normal
Target version:
[ruby-core:40489]

Description

I've built 1.9.2 from svn revision at 33531 on HP-UX/PA and HP-UX/IA. I'm getting two different results for Math.log10(10_000) depending on IA64 and PA-RISC:
(ia64)
p Math.log10(10_000)
4
(pa-risc)
p Math.log10(10_000)
3.9999999999999996

Any idea where in the code I can look to try and fix this?

History

#1 [ruby-core:40501] Updated by naruse (Yui NARUSE) almost 6 years ago

The Written Word Inc wrote:

(ia64)
p Math.log10(10_000)
4

Show the result of p 4.0.

(pa-risc)
p Math.log10(10_000)
3.9999999999999996

Build and run following C code:

% cat f.c
#include <math.h>
#include <stdio.h>

int main(void) {
  printf("%a\n", log10(10000));
  return 0;
}
%  gcc -lm f.c && ./a.out
0x1p+2 (or something)

#2 [ruby-core:40503] Updated by twwlogin (The Written Word Inc) almost 6 years ago

Yui NARUSE wrote:

The Written Word Inc wrote:

(ia64)
p Math.log10(10_000)
4

Show the result of p 4.0.

(ia64)
p 4.0
4.0
(pa-risc)
p 4.0
4.0

(pa-risc)
p Math.log10(10_000)
3.9999999999999996

Build and run following C code:

% cat f.c
#include <math.h>
#include <stdio.h>

int main(void) {
  printf("%a\n", log10(10000));
  return 0;
}
%  gcc -lm f.c && ./a.out
0x1p+2 (or something)
$ cat t.c
#include <math.h>
#include <stdio.h>

int main(void) {
  printf("%f\n", log10(10000));
  printf("%a\n", log10(10000));
  return 0; 
}
(ia64)
  $ cc +O1 +Ofltacc +Olit=all +Oentrysched +Odataprefetch -lm t.c
  $ ./a.out
  4.000000
  0x1.0000000000000p+2

%a is only supported on HP-UX/IA systems, not HP-UX/PA. We're using the HP-UX C compiler to build Ruby as well.

#3 [ruby-core:40834] Updated by naruse (Yui NARUSE) almost 6 years ago

The Written Word Inc wrote:

Yui NARUSE wrote:

The Written Word Inc wrote:

(ia64)
p Math.log10(10_000)
4

Show the result of p 4.0.

(ia64)
p 4.0
4.0

Hmm, it is strange but I don't have any idea.

(pa-risc)
p Math.log10(10_000)
3.9999999999999996

Build and run following C code:

% cat f.c
#include
#include

int main(void) {
  printf("%a\n", log10(10000));
  return 0;
}
%  gcc -lm f.c && ./a.out
0x1p+2 (or something)
$ cat t.c
#include <math.h>
#include <stdio.h>

int main(void) {
  printf("%f\n", log10(10000));
  printf("%a\n", log10(10000));
  return 0; 
}

%a is only supported on HP-UX/IA systems, not HP-UX/PA. We're using the HP-UX C compiler to build Ruby as well.

OK, can you show a result without %a?
As Bílka says, this is because it is floating point, but it can be fixed by some options to specify libm as IEEE 754 mode.

#4 [ruby-core:41042] Updated by twwlogin (The Written Word Inc) almost 6 years ago

Yui NARUSE wrote:

The Written Word Inc wrote:

$ cat t.c
#include <math.h>
#include <stdio.h>

int main(void) {
  printf("%f\n", log10(10000));
  printf("%a\n", log10(10000));
  return 0; 
}

%a is only supported on HP-UX/IA systems, not HP-UX/PA. We're using the HP-UX C compiler to build Ruby as well.

OK, can you show a result without %a?
As Bílka says, this is because it is floating point, but it can be fixed by some options to specify libm as IEEE 754 mode.

$ cat t.c
#include <math.h>
#include <stdio.h>

int main(void) {
  printf("%f\n", log10(10000));
  return 0;
} 
$ cc t.c -lm
$ ./a.out
4.000000

#5 [ruby-core:43200] Updated by ko1 (Koichi Sasada) over 5 years ago

  • Assignee set to mrkn (Kenta Murata)

#6 Updated by shyouhei (Shyouhei Urabe) over 5 years ago

  • Status changed from Open to Assigned

#7 [ruby-core:45356] Updated by mrkn (Kenta Murata) over 5 years ago

  • Status changed from Assigned to Feedback

I don't have any environments to examine this issue.
Please give me a patch to fix this.

#8 Updated by naruse (Yui NARUSE) over 4 years ago

  • Target version changed from 1.9.2 to next minor

#9 [ruby-core:81993] Updated by naruse (Yui NARUSE) 3 months ago

  • Assignee changed from mrkn (Kenta Murata) to takano32 (Mitsuhiro TAKANO)

#10 [ruby-core:81997] Updated by nobu (Nobuyoshi Nakada) 3 months ago

Please try more precision.
The default precision doesn't seem enough.

#include <math.h>
#include <stdio.h>

int main(void) {
  printf("%.19f\n", log10(10000));
  return 0;
}

Also available in: Atom PDF