Project

General

Profile

Bug #11582

On Solaris, Rational#** returns -Infinity for Rational(0) when passed a negative Float

Added by Eregon (Benoit Daloze) about 4 years ago. Updated about 4 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:<unknown>]

Description

For instance,

Rational(0, 1) ** -1.0
=> +Infinity on most platforms, -Infinity on Solaris by default.

The Rational is implicitly converted to the Float value 0.0, and the libm function pow(0.0, -1.0) is called.

Should this kind of behavior be made consistent by Ruby or should we accept this as dependent on the libm/libc used?

They are likely other edges cases for pow() which might differ, and I think in general
Ruby should try to unify these cases so the behavior is consistent across platforms at least for arithmetic.

For more details, please see https://github.com/ruby/rubyspec/issues/134 reported by ngoto.

History

#1

Updated by nobu (Nobuyoshi Nakada) about 4 years ago

Does 0.0 ** -1 return -Infinity too?
It isn't a problem?

Updated by ngoto (Naohisa Goto) about 4 years ago

Does 0.0 ** -1 return -Infinity too?

Yes, with default compiler option.
On Solaris, the 0.0 ** -1 could return 3 different values depending on compile-time options: 0, -Infinity, +Infinity.

See below for list of corner-case variations of numerical calculations.
http://docs.oracle.com/cd/E37069_01/html/E39019/z4000ac610479.html

It isn't a problem?

I don't know.

Also available in: Atom PDF