summaryrefslogtreecommitdiff
path: root/ext/-test-
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-18 00:37:10 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-18 00:37:10 +0000
commit63fee735002b34d37598d4830ef35073202dda58 (patch)
treeb6d50c223905f199bdd237b639109d4c0dcde0f1 /ext/-test-
parentddd155842fb4fd96a028836d926bae7501cbd985 (diff)
* configure.in: Check nextafter() availability.
* include/ruby/missing.h (nextafter): New optional declaration. * missing/nextafter.c: New file. * numeric.c: Float#next_float and Float#prev_float implemented. [ruby-core:62562] [Feature #9834] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45982 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/-test-')
-rw-r--r--ext/-test-/float/depend3
-rw-r--r--ext/-test-/float/extconf.rb7
-rw-r--r--ext/-test-/float/init.c11
-rw-r--r--ext/-test-/float/nextafter.c36
4 files changed, 57 insertions, 0 deletions
diff --git a/ext/-test-/float/depend b/ext/-test-/float/depend
new file mode 100644
index 0000000..dff1455
--- /dev/null
+++ b/ext/-test-/float/depend
@@ -0,0 +1,3 @@
+$(OBJS): $(HDRS) $(ruby_headers)
+
+nextafter.o: nextafter.c $(top_srcdir)/missing/nextafter.c
diff --git a/ext/-test-/float/extconf.rb b/ext/-test-/float/extconf.rb
new file mode 100644
index 0000000..0a9a299
--- /dev/null
+++ b/ext/-test-/float/extconf.rb
@@ -0,0 +1,7 @@
+$INCFLAGS << " -I$(topdir) -I$(top_srcdir)"
+$srcs = Dir[File.join($srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
+inits = $srcs.map {|s| File.basename(s, ".*")}
+inits.delete("init")
+inits.map! {|s|"X(#{s})"}
+$defs << "-DTEST_INIT_FUNCS(X)=\"#{inits.join(' ')}\""
+create_makefile("-test-/float")
diff --git a/ext/-test-/float/init.c b/ext/-test-/float/init.c
new file mode 100644
index 0000000..d962108
--- /dev/null
+++ b/ext/-test-/float/init.c
@@ -0,0 +1,11 @@
+#include "ruby.h"
+
+#define init(n) {void Init_##n(VALUE klass); Init_##n(klass);}
+
+void
+Init_float(void)
+{
+ VALUE mBug = rb_define_module("Bug");
+ VALUE klass = rb_define_class_under(mBug, "Float", rb_cObject);
+ TEST_INIT_FUNCS(init);
+}
diff --git a/ext/-test-/float/nextafter.c b/ext/-test-/float/nextafter.c
new file mode 100644
index 0000000..30fb71f
--- /dev/null
+++ b/ext/-test-/float/nextafter.c
@@ -0,0 +1,36 @@
+#include "ruby.h"
+
+static VALUE
+system_nextafter_m(VALUE klass, VALUE vx, VALUE vy)
+{
+ double x, y, z;
+
+ x = NUM2DBL(vx);
+ y = NUM2DBL(vy);
+ z = nextafter(x, y);
+
+ return DBL2NUM(z);
+}
+
+#define nextafter missing_nextafter
+#include "../../../missing/nextafter.c"
+#undef nextafter
+
+static VALUE
+missing_nextafter_m(VALUE klass, VALUE vx, VALUE vy)
+{
+ double x, y, z;
+
+ x = NUM2DBL(vx);
+ y = NUM2DBL(vy);
+ z = missing_nextafter(x, y);
+
+ return DBL2NUM(z);
+}
+
+void
+Init_nextafter(VALUE klass)
+{
+ rb_define_singleton_method(klass, "system_nextafter", system_nextafter_m, 2);
+ rb_define_singleton_method(klass, "missing_nextafter", missing_nextafter_m, 2);
+}