头文件cmath的用法

首先来看cmath头文件(VS2022上的):

// cmath standard header

// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#pragma once
#ifndef _CMATH_
#define _CMATH_
#include <yvals.h>
#if _STL_COMPILER_PREPROCESSOR

#include <cstdlib>
#include <xtr1common>

#if !defined(_M_CEE) && !defined(__clang__) && !defined(__CUDACC__) && !defined(__INTEL_COMPILER)
#define _HAS_CMATH_INTRINSICS 1
#else // ^^^ intrinsics available ^^^ / vvv intrinsics unavailable vvv
#define _HAS_CMATH_INTRINSICS 0
#endif // ^^^ intrinsics unavailable ^^^

#if _HAS_CMATH_INTRINSICS
#include <intrin0.h>
#endif // _HAS_CMATH_INTRINSICS

#if _HAS_CXX20
#include <xutility>
#endif // _HAS_CXX20

#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
#pragma warning(disable : _STL_DISABLED_WARNINGS)
_STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new

_NODISCARD _Check_return_ inline float acos(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD acosf(_Xx);
}

_NODISCARD _Check_return_ inline float acosh(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD acoshf(_Xx);
}

_NODISCARD _Check_return_ inline float asin(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD asinf(_Xx);
}

_NODISCARD _Check_return_ inline float asinh(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD asinhf(_Xx);
}

_NODISCARD _Check_return_ inline float atan(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD atanf(_Xx);
}

_NODISCARD _Check_return_ inline float atanh(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD atanhf(_Xx);
}

_NODISCARD _Check_return_ inline float atan2(_In_ float _Yx, _In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD atan2f(_Yx, _Xx);
}

_NODISCARD _Check_return_ inline float cbrt(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD cbrtf(_Xx);
}

_NODISCARD _Check_return_ inline float ceil(_In_ float _Xx) noexcept /* strengthened */ {
#if _HAS_CMATH_INTRINSICS
    return __ceilf(_Xx);
#elif defined(__clang__)
    return __builtin_ceilf(_Xx);
#else // ^^^ defined(__clang__) ^^^ / vvv intrinsics unavailable vvv
    return _CSTD ceilf(_Xx);
#endif // ^^^ intrinsics unavailable ^^^
}

_NODISCARD _Check_return_ inline float copysign(_In_ float _Number, _In_ float _Sign) noexcept /* strengthened */ {
#if _HAS_CMATH_INTRINSICS
    return __copysignf(_Number, _Sign);
#elif defined(__clang__)
    return __builtin_copysignf(_Number, _Sign);
#else // ^^^ defined(__clang__) ^^^ / vvv intrinsics unavailable vvv
    return _CSTD copysignf(_Number, _Sign);
#endif // ^^^ intrinsics unavailable ^^^
}

_NODISCARD _Check_return_ inline float cos(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD cosf(_Xx);
}

_NODISCARD _Check_return_ inline float cosh(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD coshf(_Xx);
}

_NODISCARD _Check_return_ inline float erf(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD erff(_Xx);
}

_NODISCARD _Check_return_ inline float erfc(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD erfcf(_Xx);
}

_NODISCARD _Check_return_ inline float exp(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD expf(_Xx);
}

_NODISCARD _Check_return_ inline float exp2(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD exp2f(_Xx);
}

_NODISCARD _Check_return_ inline float expm1(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD expm1f(_Xx);
}

_NODISCARD _Check_return_ inline float fabs(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD fabsf(_Xx);
}

_NODISCARD _Check_return_ inline float fdim(_In_ float _Xx, _In_ float _Yx) noexcept /* strengthened */ {
    return _CSTD fdimf(_Xx, _Yx);
}

_NODISCARD _Check_return_ inline float floor(_In_ float _Xx) noexcept /* strengthened */ {
#if _HAS_CMATH_INTRINSICS
    return __floorf(_Xx);
#elif defined(__clang__)
    return __builtin_floorf(_Xx);
#else // ^^^ defined(__clang__) ^^^ / vvv intrinsics unavailable vvv
    return _CSTD floorf(_Xx);
#endif // ^^^ intrinsics unavailable ^^^
}

_NODISCARD _Check_return_ inline float fma(_In_ float _Xx, _In_ float _Yx, _In_ float _Zx) noexcept /* strengthened */ {
    return _CSTD fmaf(_Xx, _Yx, _Zx);
}

_NODISCARD _Check_return_ inline float fmax(_In_ float _Xx, _In_ float _Yx) noexcept /* strengthened */ {
    return _CSTD fmaxf(_Xx, _Yx);
}

_NODISCARD _Check_return_ inline float fmin(_In_ float _Xx, _In_ float _Yx) noexcept /* strengthened */ {
    return _CSTD fminf(_Xx, _Yx);
}

_NODISCARD _Check_return_ inline float fmod(_In_ float _Xx, _In_ float _Yx) noexcept /* strengthened */ {
    return _CSTD fmodf(_Xx, _Yx);
}

inline float frexp(_In_ float _Xx, _Out_ int* _Yx) noexcept /* strengthened */ {
    return _CSTD frexpf(_Xx, _Yx);
}

_NODISCARD _Check_return_ inline float hypot(_In_ float _Xx, _In_ float _Yx) noexcept /* strengthened */ {
    return _CSTD hypotf(_Xx, _Yx);
}

_NODISCARD _Check_return_ inline int ilogb(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD ilogbf(_Xx);
}

_NODISCARD _Check_return_ inline float ldexp(_In_ float _Xx, _In_ int _Yx) noexcept /* strengthened */ {
    return _CSTD ldexpf(_Xx, _Yx);
}

_NODISCARD _Check_return_ inline float lgamma(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD lgammaf(_Xx);
}

_NODISCARD _Check_return_ inline long long llrint(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD llrintf(_Xx);
}

_NODISCARD _Check_return_ inline long long llround(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD llroundf(_Xx);
}

_NODISCARD _Check_return_ inline float log(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD logf(_Xx);
}

_NODISCARD _Check_return_ inline float log10(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD log10f(_Xx);
}

_NODISCARD _Check_return_ inline float log1p(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD log1pf(_Xx);
}

_NODISCARD _Check_return_ inline float log2(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD log2f(_Xx);
}

_NODISCARD _Check_return_ inline float logb(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD logbf(_Xx);
}

_NODISCARD _Check_return_ inline long lrint(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD lrintf(_Xx);
}

_NODISCARD _Check_return_ inline long lround(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD lroundf(_Xx);
}

inline float modf(_In_ float _Xx, _Out_ float* _Yx) noexcept /* strengthened */ {
    return _CSTD modff(_Xx, _Yx);
}

_NODISCARD _Check_return_ inline float nearbyint(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD nearbyintf(_Xx);
}

_NODISCARD _Check_return_ inline float nextafter(_In_ float _Xx, _In_ float _Yx) noexcept /* strengthened */ {
    return _CSTD nextafterf(_Xx, _Yx);
}

_NODISCARD _Check_return_ inline float nexttoward(_In_ float _Xx, _In_ long double _Yx) noexcept /* strengthened */ {
    return _CSTD nexttowardf(_Xx, _Yx);
}

_NODISCARD _Check_return_ inline float pow(_In_ float _Xx, _In_ float _Yx) noexcept /* strengthened */ {
    return _CSTD powf(_Xx, _Yx);
}

_NODISCARD _Check_return_ inline float remainder(_In_ float _Xx, _In_ float _Yx) noexcept /* strengthened */ {
    return _CSTD remainderf(_Xx, _Yx);
}

inline float remquo(_In_ float _Xx, _In_ float _Yx, _Out_ int* _Zx) noexcept /* strengthened */ {
    return _CSTD remquof(_Xx, _Yx, _Zx);
}

_NODISCARD _Check_return_ inline float rint(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD rintf(_Xx);
}

_NODISCARD _Check_return_ inline float round(_In_ float _Xx) noexcept /* strengthened */ {
#if _HAS_CMATH_INTRINSICS
    return __roundf(_Xx);
#elif defined(__clang__)
    return __builtin_roundf(_Xx);
#else // ^^^ defined(__clang__) ^^^ / vvv intrinsics unavailable vvv
    return _CSTD roundf(_Xx);
#endif // ^^^ intrinsics unavailable ^^^
}

_NODISCARD _Check_return_ inline float scalbln(_In_ float _Xx, _In_ long _Yx) noexcept /* strengthened */ {
    return _CSTD scalblnf(_Xx, _Yx);
}

_NODISCARD _Check_return_ inline float scalbn(_In_ float _Xx, _In_ int _Yx) noexcept /* strengthened */ {
    return _CSTD scalbnf(_Xx, _Yx);
}

_NODISCARD _Check_return_ inline float sin(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD sinf(_Xx);
}

_NODISCARD _Check_return_ inline float sinh(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD sinhf(_Xx);
}

_NODISCARD _Check_return_ inline float sqrt(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD sqrtf(_Xx);
}

_NODISCARD _Check_return_ inline float tan(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD tanf(_Xx);
}

_NODISCARD _Check_return_ inline float tanh(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD tanhf(_Xx);
}

_NODISCARD _Check_return_ inline float tgamma(_In_ float _Xx) noexcept /* strengthened */ {
    return _CSTD tgammaf(_Xx);
}

_NODISCARD _Check_return_ inline float trunc(_In_ float _Xx) noexcept /* strengthened */ {
#if _HAS_CMATH_INTRINSICS
    return __truncf(_Xx);
#elif defined(__clang__)
    return __builtin_truncf(_Xx);
#else // ^^^ defined(__clang__) ^^^ / vvv intrinsics unavailable vvv
    return _CSTD truncf(_Xx);
#endif // ^^^ intrinsics unavailable ^^^
}

_NODISCARD _Check_return_ inline long double acos(_In_ long double _Xx) noexcept /* strengthened */ {
    return _CSTD acosl(_Xx);
}

_NODISCARD _Check_return_ inline long double acosh(_In_ long double _Xx) noexcept /* strengthened */ {
    return _CSTD acoshl(_Xx);
}

_NODISCARD _Check_return_ inline long double asin(_In_ long double _Xx) noexcept /* strengthened */ {
    return _CSTD asinl(_Xx);
}

_NODISCARD _Check_return_ inline long double asinh(_In_ long double _Xx) noexcept /* strengthened */ {
    return _CSTD asinhl(_Xx);
}

_NODISCARD _Check_return_ inline long double atan(_In_ long double _Xx) noexcept /* strengthened */ {
    return _CSTD atanl(_Xx);
}

_NODISCARD _Check_return_ inline long double atanh(_In_ long double _Xx) noexcept /* strengthened */ {
    return _CSTD atanhl(_Xx);
}

_NODISCARD _Check_return_ inline long double atan2(_In_ long double _Yx, _In_ long double _Xx) noexcept
/* strengthened */ {
    return _CSTD atan2l(_Yx, _Xx);
}

_NODISCARD _Check_return_ inline long double cbrt(_In_ long double _Xx) noexcept /* strengthened */ {
    return _CSTD cbrtl(_Xx);
}

_NODISCARD _Check_return_ inline long double ceil(_In_ long double _Xx) noexcept /* strengthened */ {
#if _HAS_CMATH_INTRINSICS
    return __ceil(static_cast<double>(_Xx));
#elif defined(__clang__)
    return __builtin_ceill(_Xx);
#else // ^^^ defined(__clang__) ^^^ / vvv intrinsics unavailable vvv
    return _CSTD ceill(_Xx);
#endif // ^^^ intrinsics unavailable ^^^
}

_NODISCARD _Check_return_ inline long double copysign(_In_ long double _Number, _In_ long double _Sign) noexcept
/* strengthened */ {
#if _HAS_CMATH_INTRINSICS
    return __copysign(static_cast<double>(_Number), static_cast<double>(_Sign));
#elif defined(__clang__)
    return __builtin_copysignl(_Number, _Sign);
#else // ^^^ defined(__clang__) ^^^ / vvv intrinsics unavailable vvv
    return _CSTD copysignl(_Number, _Sign);
#endif // ^^^ intrinsics unavailable ^^^
}

_NODISCARD _Check_return_ inline long double cos(_In_ long double _Xx) noexcept /* strengthened */ {
    return _CSTD cosl(_Xx);
}

_NODISCARD _Check_return_ inline long double cosh(_In_ long double _Xx) noexcept /* strengthened */ {
    return _CSTD coshl(_Xx);
}

_NODISCARD _Check_return_ inline long double erf(_In_ long double _Xx) noexcept /* strengthened */ {
    return _CSTD erfl(_Xx);
}

_NODISCARD _Check_return_ inline long double erfc(_In_ long double _Xx) noexcept /* strengthened */ {
    return _CSTD erfcl(_Xx);
}

_
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值