Ruby  2.0.0p247(2013-06-27revision41674)
missing/hypot.c
Go to the documentation of this file.
00001 /* public domain rewrite of hypot */
00002 
00003 #include "ruby/missing.h"
00004 #include <math.h>
00005 
00006 double hypot(double x, double y)
00007 {
00008     if (x < 0) x = -x;
00009     if (y < 0) y = -y;
00010     if (x < y) {
00011         double tmp = x;
00012         x = y; y = tmp;
00013     }
00014     if (y == 0.0) return x;
00015     y /= x;
00016     return x * sqrt(1.0+y*y);
00017 }
00018