signbit.hpp

来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 87 行

HPP
87
字号
// signbit.hpp#ifndef BOOST_MATH_SIGNBIT_HPP#define BOOST_MATH_SIGNBIT_HPP// Copyright (c) 2006 Johan Rade// Distributed under the Boost Software License, Version 1.0.// (See accompanying file LICENSE_1_0.txt// or copy at http://www.boost.org/LICENSE_1_0.txt)#include "detail/fp_traits.hpp"namespace boost {namespace math {//------------------------------------------------------------------------------template<class T> bool (signbit)(T x){    typedef BOOST_DEDUCED_TYPENAME detail::fp_traits<T>::type traits;    traits::init();    BOOST_DEDUCED_TYPENAME traits::bits a;    traits::get_bits(x,a);    a &= traits::sign;    return a != 0;}//------------------------------------------------------------------------------namespace detail {    template<class T> T copysign_impl(T x, T y)    {        typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits;        traits::init();        BOOST_DEDUCED_TYPENAME traits::bits a;        traits::get_bits(x,a);        a &= ~traits::sign;        BOOST_DEDUCED_TYPENAME traits::bits b;        traits::get_bits(y,b);        b &= traits::sign;        traits::set_bits(x,a|b);        return x;    }}inline float (copysign)(float x, float y)      // magnitude of x and sign of y{    return detail::copysign_impl(x,y);}inline double (copysign)(double x, double y){    return detail::copysign_impl(x,y);}inline long double (copysign)(long double x, long double y){    return detail::copysign_impl(x,y);}//------------------------------------------------------------------------------template<class T> T (changesign)(T x){    typedef BOOST_DEDUCED_TYPENAME detail::fp_traits<T>::type traits;    traits::init();    BOOST_DEDUCED_TYPENAME traits::bits a;    traits::get_bits(x,a);    a ^= traits::sign;    traits::set_bits(x,a);    return x;}//------------------------------------------------------------------------------}   // namespace math}   // namespace boost#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?