Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use primitive for signbit

The FFI approach would lead to Valgrind erroring with jumps on
uninitialized values. This was due to GCC optimizations that would be
done with the signbit macro.

With this approach we don't get these errors and don't have to add the
ffi_util method.
  • Loading branch information...
commit b92c84f7e26f32069169e6cd66fe1ac923a8925c 1 parent 38b1bf5
@dbussink dbussink authored
View
2  kernel/common/complex.rb
@@ -280,7 +280,7 @@ def rationalize(eps = nil)
def to_s
result = real.to_s
- if imag.kind_of?(Float) ? !imag.nan? && FFI::Platform::Math.signbit(imag) != 0 : imag < 0
+ if imag.kind_of?(Float) ? !imag.nan? && imag.negative? : imag < 0
result << "-"
else
result << "+"
View
5 kernel/common/float.rb
@@ -29,6 +29,11 @@ def abs
FFI::Platform::Math.fabs(self)
end
+ def negative?
+ Rubinius.primitive :float_negative
+ raise PrimitiveFailure, "Float#negative primitive failed"
+ end
+
def +(other)
Rubinius.primitive :float_add
b, a = math_coerce other
View
2  kernel/common/float19.rb
@@ -52,7 +52,7 @@ def to_r
def arg
if nan?
self
- elsif FFI::Platform::Math.signbit(self) != 0
+ elsif negative?
Math::PI
else
0
View
1  kernel/platform/math.rb
@@ -30,7 +30,6 @@ module FFI::Platform::Math
attach_function :hypot, [:double, :double], :double
attach_function :erf, [:double], :double
attach_function :erfc, [:double], :double
- attach_function :signbit, :ffi_signbit, [:double], :int
# Rubinius-specific, used in Marshal
attach_function :modf, [:double, :pointer], :double
View
4 vm/builtin/float.cpp
@@ -459,6 +459,10 @@ namespace rubinius {
return String::create(state, str, sz);
}
+ Object* Float::negative(STATE) {
+ return signbit(this->val) ? cTrue : cFalse;
+ }
+
double Float::string_to_double(const char* buf, size_t len, bool strict, char** end) {
int flags = double_conversion::StringToDoubleConverter::ALLOW_HEX |
double_conversion::StringToDoubleConverter::ALLOW_TRAILING_SPACES;
View
3  vm/builtin/float.hpp
@@ -129,6 +129,9 @@ namespace rubinius {
// Rubinius.primitive :float_to_packed
String* to_packed(STATE, Object* want_double);
+ // Rubinius.primitive :float_negative
+ Object* negative(STATE);
+
static int radix() { return FLT_RADIX; }
static int rounds() { return FLT_ROUNDS; }
static double min() { return DBL_MIN; }
View
4 vm/ffi_util.cpp
@@ -47,8 +47,4 @@ long ffi_minor(dev_t n) {
return minor(n);
}
-int ffi_signbit(double x) {
- return signbit(x);
-}
-
}
View
4 vm/missing/math.h
@@ -16,4 +16,8 @@
#define isnan std::isnan
#endif
+#ifndef signbit
+#define signbit std::signbit
+#endif
+
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.