Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rename Float#negative? to Float#signbit?
Ruby 2.3 ships with a new `Numeric#negative?` method. Rubinius implements
this method since b92c84f, for internal usage though ; it delegates to
the signbit C++ function.

However, `signbit`'s behavior can't match MRI `Float#negative?`'s one
since the former operates on the sign while the latter operates on the
value (see http://git.io/vm1fg).
  • Loading branch information
robin850 authored and Yorick Peterse committed Jul 18, 2015
1 parent 9088c10 commit 533da7e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion kernel/common/complex.rb
Expand Up @@ -277,7 +277,7 @@ def rationalize(eps = nil)
def to_s
result = real.to_s

if imag.kind_of?(Float) ? !imag.nan? && imag.negative? : imag < 0
if imag.kind_of?(Float) ? !imag.nan? && imag.signbit? : imag < 0
result << "-"
else
result << "+"
Expand Down
8 changes: 4 additions & 4 deletions kernel/common/float.rb
Expand Up @@ -57,7 +57,7 @@ def to_r
def arg
if nan?
self
elsif negative?
elsif signbit?
Math::PI
else
0
Expand Down Expand Up @@ -118,9 +118,9 @@ def abs

alias_method :magnitude, :abs

def negative?
Rubinius.primitive :float_negative
raise PrimitiveFailure, "Float#negative primitive failed"
def signbit?
Rubinius.primitive :float_signbit_p
raise PrimitiveFailure, "Float#signbit? primitive failed"
end

def +(other)
Expand Down
2 changes: 1 addition & 1 deletion vm/builtin/float.cpp
Expand Up @@ -457,7 +457,7 @@ namespace rubinius {
return String::create(state, str, sz);
}

Object* Float::negative(STATE) {
Object* Float::signbit_p(STATE) {
return signbit(this->val) ? cTrue : cFalse;
}

Expand Down
4 changes: 2 additions & 2 deletions vm/builtin/float.hpp
Expand Up @@ -129,8 +129,8 @@ namespace rubinius {
// Rubinius.primitive :float_to_packed
String* to_packed(STATE, Object* want_double);

// Rubinius.primitive :float_negative
Object* negative(STATE);
// Rubinius.primitive :float_signbit_p
Object* signbit_p(STATE);

static int radix() { return FLT_RADIX; }
static int rounds() { return FLT_ROUNDS; }
Expand Down

0 comments on commit 533da7e

Please sign in to comment.