<commit_before>// SPDX-License-Identifier: MIT
// Copyright (c) 2015-2021 Zig Contributors
// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
// The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
// https://git.musl-libc.org/cgit/musl/tree/src/math/hypotf.c
// https://git.musl-libc.org/cgit/musl/tree/src/math/hypot.c

const std = @import("../std.zig");
const math = std.math;
const expect = std.testing.expect;
const maxInt = std.math.maxInt;

/// Returns sqrt(x * x + y * y), avoiding unncessary overflow and underflow.
///
/// Special Cases:
///  - hypot(+-inf, y)  = +inf
///  - hypot(x, +-inf)  = +inf
///  - hypot(nan, y)    = nan
///  - hypot(x, nan)    = nan
pub fn hypot(comptime T: type, x: T, y: T) T {
    return switch (T) {
        f32 => hypot32(x, y),
        f64 => hypot64(x, y),
        else => @compileError("hypot not implemented for " ++ @typeName(T)),
    };
}

fn hypot32(x: f32, y: f32) f32 {
    var ux = @bitCast(u32, x);
    var uy = @bitCast(u32, y);

    ux &= maxInt(u32) >> 1;
    uy &= maxInt(u32) >> 1;
    if (ux < uy) {
        const tmp = ux;
        ux = uy;
        uy = tmp;
    }

    var xx = @bitCast(f32, ux);
    var yy = @bitCast(f32, uy);
    if (uy == 0xFF << 23) {<commit_msg>FIX typo in doc comment for std.math.hypot (#9413)<commit_after>// SPDX-License-Identifier: MIT
// Copyright (c) 2015-2021 Zig Contributors
// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
// The MIT license requires this copyright notice to be included in all copies
// and substantial portions of the software.
// Ported from musl, which is licensed under the MIT license:
// https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
//
// https://git.musl-libc.org/cgit/musl/tree/src/math/hypotf.c
// https://git.musl-libc.org/cgit/musl/tree/src/math/hypot.c

const std = @import("../std.zig");
const math = std.math;
const expect = std.testing.expect;
const maxInt = std.math.maxInt;

/// Returns sqrt(x * x + y * y), avoiding unnecessary overflow and underflow.
///
/// Special Cases:
///  - hypot(+-inf, y)  = +inf
///  - hypot(x, +-inf)  = +inf
///  - hypot(nan, y)    = nan
///  - hypot(x, nan)    = nan
pub fn hypot(comptime T: type, x: T, y: T) T {
    return switch (T) {
        f32 => hypot32(x, y),
        f64 => hypot64(x, y),
        else => @compileError("hypot not implemented for " ++ @typeName(T)),
    };
}

fn hypot32(x: f32, y: f32) f32 {
    var ux = @bitCast(u32, x);
    var uy = @bitCast(u32, y);

    ux &= maxInt(u32) >> 1;
    uy &= maxInt(u32) >> 1;
    if (ux < uy) {
        const tmp = ux;
        ux = uy;
        uy = tmp;
    }

    var xx = @bitCast(f32, ux);
    var yy = @bitCast(f32, uy);
    if (uy == 0xFF << 23) {
{'fraction_non_alphanumeric': 0.1778615490061686, 'fraction_numerical': 0.029472241261137764, 'mean_word_length': 2.450354609929078, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7282890', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1094, 'n_words': 313}