Skip to content

Commit 533da7e

Browse files
robin850Yorick Peterse
authored and
Yorick Peterse
committedJul 18, 2015
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).
1 parent 9088c10 commit 533da7e

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed
 

‎kernel/common/complex.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def rationalize(eps = nil)
277277
def to_s
278278
result = real.to_s
279279

280-
if imag.kind_of?(Float) ? !imag.nan? && imag.negative? : imag < 0
280+
if imag.kind_of?(Float) ? !imag.nan? && imag.signbit? : imag < 0
281281
result << "-"
282282
else
283283
result << "+"

‎kernel/common/float.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def to_r
5757
def arg
5858
if nan?
5959
self
60-
elsif negative?
60+
elsif signbit?
6161
Math::PI
6262
else
6363
0
@@ -118,9 +118,9 @@ def abs
118118

119119
alias_method :magnitude, :abs
120120

121-
def negative?
122-
Rubinius.primitive :float_negative
123-
raise PrimitiveFailure, "Float#negative primitive failed"
121+
def signbit?
122+
Rubinius.primitive :float_signbit_p
123+
raise PrimitiveFailure, "Float#signbit? primitive failed"
124124
end
125125

126126
def +(other)

‎vm/builtin/float.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ namespace rubinius {
457457
return String::create(state, str, sz);
458458
}
459459

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

‎vm/builtin/float.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ namespace rubinius {
129129
// Rubinius.primitive :float_to_packed
130130
String* to_packed(STATE, Object* want_double);
131131

132-
// Rubinius.primitive :float_negative
133-
Object* negative(STATE);
132+
// Rubinius.primitive :float_signbit_p
133+
Object* signbit_p(STATE);
134134

135135
static int radix() { return FLT_RADIX; }
136136
static int rounds() { return FLT_ROUNDS; }

0 commit comments

Comments
 (0)
Please sign in to comment.