Forum: Ruby-core [ruby-trunk - Bug #7682][Open] Inconsistent results when using variables versus raw floats in expone

Posted by ccashwell (Chris Cashwell) (Guest)
on 2013-01-10 21:51
(Received via mailing list)
Issue #7682 has been reported by ccashwell (Chris Cashwell).

----------------------------------------
Bug #7682: Inconsistent results when using variables versus raw floats 
in exponential calculations
https://bugs.ruby-lang.org/issues/7682

Author: ccashwell (Chris Cashwell)
Status: Open
Priority: Normal
Assignee:
Category:
Target version: 1.9.3
ruby -v: ruby 1.9.3p194 (2012-04-20 revision 35410) 
[x86_64-darwin11.4.0]


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.
Posted by charliesome (Charlie Somerville) (Guest)
on 2013-01-10 22:24
(Received via mailing list)
Issue #7682 has been updated by charliesome (Charlie Somerville).

Status changed from Open to Rejected

=begin
The (({**})) operator has a higher precedence than unary minus, so your 
example is actually (({-(4.5 ** 0.5)})).
=end
----------------------------------------
Bug #7682: Inconsistent results when using variables versus raw floats 
in exponential calculations
https://bugs.ruby-lang.org/issues/7682#change-35336

Author: ccashwell (Chris Cashwell)
Status: Rejected
Priority: Normal
Assignee:
Category:
Target version: 1.9.3
ruby -v: ruby 1.9.3p194 (2012-04-20 revision 35410) 
[x86_64-darwin11.4.0]


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.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.