Project

General

Profile

Actions

Bug #7682

closed

Inconsistent results when using variables versus raw floats in exponential calculations

Added by ccashwell (Chris Cashwell) almost 12 years ago. Updated almost 12 years ago.

Status:
Rejected
Assignee:
-
Target version:
ruby -v:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
Backport:
[ruby-core:51367]

Description

When performing exponential calculations using a negative number as the base, inconsistent results are returned when using the raw value as opposed to a variable containing the value.

In IRB:

1.9.3p194 :001 > -4.5 ** 0.5
=> -2.1213203435596424
1.9.3p194 :002 > foo = -4.5
=> -4.5
1.9.3p194 :003 > foo ** 0.5
=> (1.2989340843532398e-16+2.1213203435596424i)

The expected behavior is that these two calculations should be equivalent. The compiler treats the - sign differently when using an inline float versus a variable float.

Actions

Also available in: Atom PDF

Like0
Like0