Ruby 3.5.0dev (2025-08-16 revision 4d0836d928839ff13580f5e5b74a40b3914d9f59)
hypot.c
1/* public domain rewrite of hypot */
2
3#include "ruby/missing.h"
4#include <math.h>
5
6double hypot(double x, double y)
7{
8 if (x < 0) x = -x;
9 if (y < 0) y = -y;
10 if (x < y) {
11 double tmp = x;
12 x = y; y = tmp;
13 }
14 if (y == 0.0) return x;
15 y /= x;
16 return x * sqrt(1.0+y*y);
17}