/** * D header file for C99. * * $(C_HEADER_DESCRIPTION pubs.opengroup.org/onlinepubs/009695399/basedefs/_math.h.html, _math.h) * * Copyright: Copyright Sean Kelly 2005 - 2012. * License: Distributed under the * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0). * (See accompanying file LICENSE) * Authors: Sean Kelly * Source: $(DRUNTIMESRC core/stdc/_math.d) */ module core.stdc.math; import core.stdc.config; version (OSX) version = Darwin;else version (iOS) version = Darwin;else version (TVOS) version = Darwin;else version (WatchOS) version = Darwin; version (ARM) version = ARM_Any;version (AArch64) version = ARM_Any;version (HPPA) version = HPPA_Any;version (MIPS32) version = MIPS_Any;version (MIPS64) version = MIPS_Any;version (PPC) version = PPC_Any;version (PPC64) version = PPC_Any;version (RISCV32) version = RISCV_Any;version (RISCV64) version = RISCV_Any;version (S390) version = IBMZ_Any;version (SPARC) version = SPARC_Any;version (SPARC64) version = SPARC_Any;version (SystemZ) version = IBMZ_Any;version (X86) version = X86_Any;version (X86_64) version = X86_Any; extern (C):@trusted: // All functions here operate on floating point and integer values only.nothrow:@nogc: ///alias float_t = float;///alias double_t = double; ///enum double HUGE_VAL = double.infinity;///enum double HUGE_VALF = float.infinity;///enum double HUGE_VALL = real.infinity; ///enum float INFINITY = float.infinity;///enum float NAN = float.nan; version (FreeBSD){ /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max;}else version (NetBSD){ /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max;}else version (OpenBSD){ /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max;}else version (DragonFlyBSD){ /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max;}else version (Solaris){ /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max;}else version (CRuntime_Bionic){ /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max;}else version (CRuntime_UClibc){ version (X86_Any) { /// enum int FP_ILOGB0 = int.min; /// enum int FP_ILOGBNAN = int.min; } else version (MIPS_Any) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (ARM) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else { static assert(false, "Architecture not supported."); }}else version (CRuntime_Glibc){ version (X86_Any) { /// enum int FP_ILOGB0 = int.min; /// enum int FP_ILOGBNAN = int.min; } else version (ARM_Any) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (HPPA_Any) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (MIPS_Any) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (PPC_Any) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (RISCV_Any) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (SPARC_Any) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (IBMZ_Any) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (LoongArch64) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else { static assert(false, "Architecture not supported."); }}else{ /// enum int FP_ILOGB0 = int.min; /// enum int FP_ILOGBNAN = int.min;} ///enum int MATH_ERRNO = 1;///enum int MATH_ERREXCEPT = 2;///enum int math_errhandling = MATH_ERRNO | MATH_ERREXCEPT; version (none){ // // these functions are all macros in C // //int fpclassify(real-floating x); pure int fpclassify(float x); pure int fpclassify(double x); pure int fpclassify(real x); //int isfinite(real-floating x); pure int isfinite(float x); pure int isfinite(double x); pure int isfinite(real x); //int isinf(real-floating x); pure int isinf(float x); pure int isinf(double x); pure int isinf(real x); //int isnan(real-floating x); pure int isnan(float x); pure int isnan(double x); pure int isnan(real x); //int isnormal(real-floating x); pure int isnormal(float x); pure int isnormal(double x); pure int isnormal(real x); //int signbit(real-floating x); pure int signbit(float x); pure int signbit(double x); pure int signbit(real x); //int isgreater(real-floating x, real-floating y); pure int isgreater(float x, float y); pure int isgreater(double x, double y); pure int isgreater(real x, real y); //int isgreaterequal(real-floating x, real-floating y); pure int isgreaterequal(float x, float y); pure int isgreaterequal(double x, double y); pure int isgreaterequal(real x, real y); //int isless(real-floating x, real-floating y); pure int isless(float x, float y); pure int isless(double x, double y); pure int isless(real x, real y); //int islessequal(real-floating x, real-floating y); pure int islessequal(float x, float y); pure int islessequal(double x, double y); pure int islessequal(real x, real y); //int islessgreater(real-floating x, real-floating y); pure int islessgreater(float x, float y); pure int islessgreater(double x, double y); pure int islessgreater(real x, real y); //int isunordered(real-floating x, real-floating y); pure int isunordered(float x, float y); pure int isunordered(double x, double y); pure int isunordered(real x, real y);} version (CRuntime_Microsoft) // fully supported since MSVCRT 12 (VS 2013) only{ version (all) // legacy stuff to be removed in the future { enum { _FPCLASS_SNAN = 1, _FPCLASS_QNAN = 2, _FPCLASS_NINF = 4, _FPCLASS_NN = 8, _FPCLASS_ND = 0x10, _FPCLASS_NZ = 0x20, _FPCLASS_PZ = 0x40, _FPCLASS_PD = 0x80, _FPCLASS_PN = 0x100, _FPCLASS_PINF = 0x200, } //deprecated("Please use the standard C99 function copysignf() instead.") pure float _copysignf(float x, float s); //deprecated("_chgsignf(x) is a non-standard MS extension. Please consider using -x instead.") pure float _chgsignf(float x); version (Win64) // not available in 32-bit runtimes { //deprecated("Please use the standard C99 function isfinite() instead.") pure int _finitef(float x); //deprecated("Please use the standard C99 function isnan() instead.") pure int _isnanf(float x); //deprecated("Please use the standard C99 function fpclassify() instead.") pure int _fpclassf(float x); } //deprecated("Please use the standard C99 function copysign() instead.") pure double _copysign(double x, double s); //deprecated("_chgsign(x) is a non-standard MS extension. Please consider using -x instead.") pure double _chgsign(double x); //deprecated("Please use the standard C99 function isfinite() instead.") pure int _finite(double x); //deprecated("Please use the standard C99 function isnan() instead.") pure int _isnan(double x); //deprecated("Please use the standard C99 function fpclassify() instead.") pure int _fpclass(double x); } version (MinGW) { enum { /// FP_NAN = 0x0100, /// FP_NORMAL = 0x0400, /// FP_INFINITE = FP_NAN | FP_NORMAL, /// FP_ZERO = 0x0400, /// FP_SUBNORMAL = FP_NORMAL | FP_ZERO } pure int __fpclassifyf(float x); pure int __fpclassify(double x); pure int __fpclassifyl(real x); pure int __isnanf(float x); pure int __isnan(double x); pure int __isnanl(real x); pure int __signbitf(float x); pure int __signbit(double x); pure int __signbitl(real x); //int fpclassify(real-floating x); /// pragma(mangle, "__fpclassifyf") pure int fpclassify(float x); /// pragma(mangle, "__fpclassify") pure int fpclassify(double x); /// pragma(mangle, real.sizeof == double.sizeof ? "__fpclassify" : "__fpclassifyl") pure int fpclassify(real x); extern (D) { //int isfinite(real-floating x); /// pure int isfinite(float x) { return (fpclassify(x) & FP_NORMAL) == 0; } /// pure int isfinite(double x) { return (fpclassify(x) & FP_NORMAL) == 0; } /// pure int isfinite(real x) { return (fpclassify(x) & FP_NORMAL) == 0; } //int isinf(real-floating x); /// pure int isinf(float x) { return fpclassify(x) == FP_INFINITE; } /// pure int isinf(double x) { return fpclassify(x) == FP_INFINITE; } /// pure int isinf(real x) { return fpclassify(x) == FP_INFINITE; } } //int isnan(real-floating x); /// pragma(mangle, "__isnanf") pure int isnan(float x); /// pragma(mangle, "__isnan") pure int isnan(double x); /// pragma(mangle, real.sizeof == double.sizeof ? "__isnan" : "__isnanl") pure int isnan(real x); extern (D) { //int isnormal(real-floating x); /// int isnormal(float x) { return fpclassify(x) == FP_NORMAL; } /// int isnormal(double x) { return fpclassify(x) == FP_NORMAL; } /// int isnormal(real x) { return fpclassify(x) == FP_NORMAL; } } //int signbit(real-floating x); /// pragma(mangle, "__signbitf") pure int signbit(float x); /// pragma(mangle, "__signbit") pure int signbit(double x); /// pragma(mangle, real.sizeof == double.sizeof ? "__signbit" : "__signbitl") int signbit(real x); } else { enum { /// FP_SUBNORMAL = -2, /// FP_NORMAL = -1, /// FP_ZERO = 0, /// FP_INFINITE = 1, /// FP_NAN = 2, } extern(D) { //int fpclassify(real-floating x); /// extern(C) pragma(mangle, "_fdclass") pure int fpclassify(float x); /// extern(C) pragma(mangle, "_dclass") pure int fpclassify(double x); /// pure int fpclassify()(real x) { static if (real.sizeof == double.sizeof) return fpclassify(cast(double) x); else static assert(false, "fpclassify(real) not supported by MS C runtime"); } //int isfinite(real-floating x); /// pure int isfinite()(float x) { return fpclassify(x) <= 0; } /// pure int isfinite()(double x) { return fpclassify(x) <= 0; } /// pure int isfinite()(real x) { return fpclassify(x) <= 0; } //int isinf(real-floating x); /// pure int isinf()(float x) { return fpclassify(x) == FP_INFINITE; } /// pure int isinf()(double x) { return fpclassify(x) == FP_INFINITE; } /// pure int isinf()(real x) { return fpclassify(x) == FP_INFINITE; } //int isnan(real-floating x); version (none) // requires MSVCRT 12+ (VS 2013) { /// pure int isnan(float x) { return fpclassify(x) == FP_NAN; } /// pure int isnan(double x) { return fpclassify(x) == FP_NAN; } /// pure int isnan(real x) { return fpclassify(x) == FP_NAN; } } else // for backward compatibility with older runtimes { /// pure int isnan(float x) { version (Win64) return _isnanf(x); else return _isnan(cast(double) x); } /// extern(C) pragma(mangle, "_isnan") pure int isnan(double x); /// pure int isnan(real x) { return _isnan(cast(double) x); } } //int isnormal(real-floating x); /// pure int isnormal()(float x) { return fpclassify(x) == FP_NORMAL; } /// pure int isnormal()(double x) { return fpclassify(x) == FP_NORMAL; } /// pure int isnormal()(real x) { return fpclassify(x) == FP_NORMAL; } //int signbit(real-floating x);Lines 1–500 of 4934. Load more
/** * D header file for C99. * * $(C_HEADER_DESCRIPTION pubs.opengroup.org/onlinepubs/009695399/basedefs/_math.h.html, _math.h) * * Copyright: Copyright Sean Kelly 2005 - 2012. * License: Distributed under the * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0). * (See accompanying file LICENSE) * Authors: Sean Kelly * Source: $(DRUNTIMESRC core/stdc/_math.d) */ module core.stdc.math; import core.stdc.config; version (OSX) version = Darwin; else version (iOS) version = Darwin; else version (TVOS) version = Darwin; else version (WatchOS) version = Darwin; version (ARM) version = ARM_Any; version (AArch64) version = ARM_Any; version (HPPA) version = HPPA_Any; version (MIPS32) version = MIPS_Any; version (MIPS64) version = MIPS_Any; version (PPC) version = PPC_Any; version (PPC64) version = PPC_Any; version (RISCV32) version = RISCV_Any; version (RISCV64) version = RISCV_Any; version (S390) version = IBMZ_Any; version (SPARC) version = SPARC_Any; version (SPARC64) version = SPARC_Any; version (SystemZ) version = IBMZ_Any; version (X86) version = X86_Any; version (X86_64) version = X86_Any; extern (C): @trusted: // All functions here operate on floating point and integer values only. nothrow: @nogc: /// alias float_t = float; /// alias double_t = double; /// enum double HUGE_VAL = double.infinity; /// enum double HUGE_VALF = float.infinity; /// enum double HUGE_VALL = real.infinity; /// enum float INFINITY = float.infinity; /// enum float NAN = float.nan; version (FreeBSD) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (NetBSD) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (OpenBSD) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (DragonFlyBSD) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (Solaris) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (CRuntime_Bionic) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (CRuntime_UClibc) { version (X86_Any) { /// enum int FP_ILOGB0 = int.min; /// enum int FP_ILOGBNAN = int.min; } else version (MIPS_Any) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (ARM) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else { static assert(false, "Architecture not supported."); } } else version (CRuntime_Glibc) { version (X86_Any) { /// enum int FP_ILOGB0 = int.min; /// enum int FP_ILOGBNAN = int.min; } else version (ARM_Any) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (HPPA_Any) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (MIPS_Any) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (PPC_Any) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (RISCV_Any) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (SPARC_Any) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (IBMZ_Any) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else version (LoongArch64) { /// enum int FP_ILOGB0 = -int.max; /// enum int FP_ILOGBNAN = int.max; } else { static assert(false, "Architecture not supported."); } } else { /// enum int FP_ILOGB0 = int.min; /// enum int FP_ILOGBNAN = int.min; } /// enum int MATH_ERRNO = 1; /// enum int MATH_ERREXCEPT = 2; /// enum int math_errhandling = MATH_ERRNO | MATH_ERREXCEPT; version (none) { // // these functions are all macros in C // //int fpclassify(real-floating x); pure int fpclassify(float x); pure int fpclassify(double x); pure int fpclassify(real x); //int isfinite(real-floating x); pure int isfinite(float x); pure int isfinite(double x); pure int isfinite(real x); //int isinf(real-floating x); pure int isinf(float x); pure int isinf(double x); pure int isinf(real x); //int isnan(real-floating x); pure int isnan(float x); pure int isnan(double x); pure int isnan(real x); //int isnormal(real-floating x); pure int isnormal(float x); pure int isnormal(double x); pure int isnormal(real x); //int signbit(real-floating x); pure int signbit(float x); pure int signbit(double x); pure int signbit(real x); //int isgreater(real-floating x, real-floating y); pure int isgreater(float x, float y); pure int isgreater(double x, double y); pure int isgreater(real x, real y); //int isgreaterequal(real-floating x, real-floating y); pure int isgreaterequal(float x, float y); pure int isgreaterequal(double x, double y); pure int isgreaterequal(real x, real y); //int isless(real-floating x, real-floating y); pure int isless(float x, float y); pure int isless(double x, double y); pure int isless(real x, real y); //int islessequal(real-floating x, real-floating y); pure int islessequal(float x, float y); pure int islessequal(double x, double y); pure int islessequal(real x, real y); //int islessgreater(real-floating x, real-floating y); pure int islessgreater(float x, float y); pure int islessgreater(double x, double y); pure int islessgreater(real x, real y); //int isunordered(real-floating x, real-floating y); pure int isunordered(float x, float y); pure int isunordered(double x, double y); pure int isunordered(real x, real y); } version (CRuntime_Microsoft) // fully supported since MSVCRT 12 (VS 2013) only { version (all) // legacy stuff to be removed in the future { enum { _FPCLASS_SNAN = 1, _FPCLASS_QNAN = 2, _FPCLASS_NINF = 4, _FPCLASS_NN = 8, _FPCLASS_ND = 0x10, _FPCLASS_NZ = 0x20, _FPCLASS_PZ = 0x40, _FPCLASS_PD = 0x80, _FPCLASS_PN = 0x100, _FPCLASS_PINF = 0x200, } //deprecated("Please use the standard C99 function copysignf() instead.") pure float _copysignf(float x, float s); //deprecated("_chgsignf(x) is a non-standard MS extension. Please consider using -x instead.") pure float _chgsignf(float x); version (Win64) // not available in 32-bit runtimes { //deprecated("Please use the standard C99 function isfinite() instead.") pure int _finitef(float x); //deprecated("Please use the standard C99 function isnan() instead.") pure int _isnanf(float x); //deprecated("Please use the standard C99 function fpclassify() instead.") pure int _fpclassf(float x); } //deprecated("Please use the standard C99 function copysign() instead.") pure double _copysign(double x, double s); //deprecated("_chgsign(x) is a non-standard MS extension. Please consider using -x instead.") pure double _chgsign(double x); //deprecated("Please use the standard C99 function isfinite() instead.") pure int _finite(double x); //deprecated("Please use the standard C99 function isnan() instead.") pure int _isnan(double x); //deprecated("Please use the standard C99 function fpclassify() instead.") pure int _fpclass(double x); } version (MinGW) { enum { /// FP_NAN = 0x0100, /// FP_NORMAL = 0x0400, /// FP_INFINITE = FP_NAN | FP_NORMAL, /// FP_ZERO = 0x0400, /// FP_SUBNORMAL = FP_NORMAL | FP_ZERO } pure int __fpclassifyf(float x); pure int __fpclassify(double x); pure int __fpclassifyl(real x); pure int __isnanf(float x); pure int __isnan(double x); pure int __isnanl(real x); pure int __signbitf(float x); pure int __signbit(double x); pure int __signbitl(real x); //int fpclassify(real-floating x); /// pragma(mangle, "__fpclassifyf") pure int fpclassify(float x); /// pragma(mangle, "__fpclassify") pure int fpclassify(double x); /// pragma(mangle, real.sizeof == double.sizeof ? "__fpclassify" : "__fpclassifyl") pure int fpclassify(real x); extern (D) { //int isfinite(real-floating x); /// pure int isfinite(float x) { return (fpclassify(x) & FP_NORMAL) == 0; } /// pure int isfinite(double x) { return (fpclassify(x) & FP_NORMAL) == 0; } /// pure int isfinite(real x) { return (fpclassify(x) & FP_NORMAL) == 0; } //int isinf(real-floating x); /// pure int isinf(float x) { return fpclassify(x) == FP_INFINITE; } /// pure int isinf(double x) { return fpclassify(x) == FP_INFINITE; } /// pure int isinf(real x) { return fpclassify(x) == FP_INFINITE; } } //int isnan(real-floating x); /// pragma(mangle, "__isnanf") pure int isnan(float x); /// pragma(mangle, "__isnan") pure int isnan(double x); /// pragma(mangle, real.sizeof == double.sizeof ? "__isnan" : "__isnanl") pure int isnan(real x); extern (D) { //int isnormal(real-floating x); /// int isnormal(float x) { return fpclassify(x) == FP_NORMAL; } /// int isnormal(double x) { return fpclassify(x) == FP_NORMAL; } /// int isnormal(real x) { return fpclassify(x) == FP_NORMAL; } } //int signbit(real-floating x); /// pragma(mangle, "__signbitf") pure int signbit(float x); /// pragma(mangle, "__signbit") pure int signbit(double x); /// pragma(mangle, real.sizeof == double.sizeof ? "__signbit" : "__signbitl") int signbit(real x); } else { enum { /// FP_SUBNORMAL = -2, /// FP_NORMAL = -1, /// FP_ZERO = 0, /// FP_INFINITE = 1, /// FP_NAN = 2, } extern(D) { //int fpclassify(real-floating x); /// extern(C) pragma(mangle, "_fdclass") pure int fpclassify(float x); /// extern(C) pragma(mangle, "_dclass") pure int fpclassify(double x); /// pure int fpclassify()(real x) { static if (real.sizeof == double.sizeof) return fpclassify(cast(double) x); else static assert(false, "fpclassify(real) not supported by MS C runtime"); } //int isfinite(real-floating x); /// pure int isfinite()(float x) { return fpclassify(x) <= 0; } /// pure int isfinite()(double x) { return fpclassify(x) <= 0; } /// pure int isfinite()(real x) { return fpclassify(x) <= 0; } //int isinf(real-floating x); /// pure int isinf()(float x) { return fpclassify(x) == FP_INFINITE; } /// pure int isinf()(double x) { return fpclassify(x) == FP_INFINITE; } /// pure int isinf()(real x) { return fpclassify(x) == FP_INFINITE; } //int isnan(real-floating x); version (none) // requires MSVCRT 12+ (VS 2013) { /// pure int isnan(float x) { return fpclassify(x) == FP_NAN; } /// pure int isnan(double x) { return fpclassify(x) == FP_NAN; } /// pure int isnan(real x) { return fpclassify(x) == FP_NAN; } } else // for backward compatibility with older runtimes { /// pure int isnan(float x) { version (Win64) return _isnanf(x); else return _isnan(cast(double) x); } /// extern(C) pragma(mangle, "_isnan") pure int isnan(double x); /// pure int isnan(real x) { return _isnan(cast(double) x); } } //int isnormal(real-floating x); /// pure int isnormal()(float x) { return fpclassify(x) == FP_NORMAL; } /// pure int isnormal()(double x) { return fpclassify(x) == FP_NORMAL; } /// pure int isnormal()(real x) { return fpclassify(x) == FP_NORMAL; } //int signbit(real-floating x);