Skip to content
Permalink
Browse files
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 YorickPeterse committed Jul 18, 2015
1 parent 9088c10 commit 533da7eadbf65d7ad14ac74e6d491560c1814293
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
@@ -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 << "+"
@@ -57,7 +57,7 @@ def to_r
def arg
if nan?
self
elsif negative?
elsif signbit?
Math::PI
else
0
@@ -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)
@@ -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;
}

@@ -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; }

0 comments on commit 533da7e

Please sign in to comment.