The OpenD Programming Language

hypot

Calculates the distance of the point (x, y, z) from the origin (0, 0, 0) in three-dimensional space. The distance is the value of the square root of the sums of the squares of x, y, and z:

sqrt(x2 + y2 + z2)

Note that the distance between two points (x1, y1, z1) and (x2, y2, z2) in three-dimensional space can be calculated as hypot(x2-x1, y2-y1, z2-z1).

  1. T hypot(T x, T y)
  2. T hypot(T x, T y, T z)
    @safe pure nothrow @nogc
    T
    hypot
    (
    T
    )
    (
    const T x
    ,
    const T y
    ,
    const T z
    )

Parameters

x T

floating point value

y T

floating point value

z T

floating point value

Return Value

Type: T

The square root of the sum of the squares of the given arguments.

Examples

import std.math.operations : isClose;

assert(isClose(hypot(1.0, 2.0, 2.0), 3.0));
assert(isClose(hypot(2.0, 3.0, 6.0), 7.0));
assert(isClose(hypot(1.0, 4.0, 8.0), 9.0));

Meta