summaryrefslogtreecommitdiff
path: root/jni/ruby/missing/hypot.c
diff options
context:
space:
mode:
Diffstat (limited to 'jni/ruby/missing/hypot.c')
-rw-r--r--jni/ruby/missing/hypot.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/jni/ruby/missing/hypot.c b/jni/ruby/missing/hypot.c
new file mode 100644
index 0000000..765581b
--- /dev/null
+++ b/jni/ruby/missing/hypot.c
@@ -0,0 +1,17 @@
+/* public domain rewrite of hypot */
+
+#include "ruby/missing.h"
+#include <math.h>
+
+double hypot(double x, double y)
+{
+ if (x < 0) x = -x;
+ if (y < 0) y = -y;
+ if (x < y) {
+ double tmp = x;
+ x = y; y = tmp;
+ }
+ if (y == 0.0) return x;
+ y /= x;
+ return x * sqrt(1.0+y*y);
+}