GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::copysign,std::copysignf,std::copysignl(3) C++ Standard Libary std::copysign,std::copysignf,std::copysignl(3)

std::copysign,std::copysignf,std::copysignl - std::copysign,std::copysignf,std::copysignl


Defined in header <cmath>
float copysign ( float mag, float sgn ); (1) (since C++11)
(constexpr since C++23)
float copysignf( float mag, float sgn ); (2) (since C++11)
(constexpr since C++23)
double copysign ( double mag, double sgn ); (3) (since C++11)
(constexpr since C++23)
long double copysign ( long double mag, long double sgn (4) (since C++11)
); (constexpr since C++23)
long double copysignl( long double mag, long double sgn (5) (since C++11)
); (constexpr since C++23)
Promoted copysign ( Arithmetic1 mag, Arithmetic2 sgn ); (6) (since C++11)
(constexpr since C++23)


1-5) Composes a floating point value with the magnitude of mag and the sign of sgn.
6) A set of overloads or a function template for all combinations of arguments of
arithmetic type not covered by (1-5). If any argument has integral type, it is cast
to double. If any argument is long double, then the return type Promoted is also
long double, otherwise the return type is always double.


mag, sgn - floating point values


If no errors occur, the floating point value with the magnitude of mag and the sign
of sgn is returned.


If mag is NaN, then NaN with the sign of sgn is returned.


If sgn is -0, the result is only negative if the implementation supports the signed
zero consistently in arithmetic operations.


This function is not subject to any errors specified in math_errhandling.


If the implementation supports IEEE floating-point arithmetic (IEC 60559),


* The returned value is exact (FE_INEXACT is never raised) and independent of the
current rounding mode.


std::copysign is the only portable way to manipulate the sign of a NaN value (to
examine the sign of a NaN, signbit may also be used)

// Run this code


#include <iostream>
#include <cmath>


int main(void)
{
std::cout << std::showpos
<< "copysign(1.0,+2.0) = " << std::copysign(1.0,+2.0) << '\n'
<< "copysign(1.0,-2.0) = " << std::copysign(1.0,-2.0) << '\n'
<< "copysign(inf,-2.0) = " << std::copysign(INFINITY,-2.0) << '\n'
<< "copysign(NaN,-2.0) = " << std::copysign(NAN,-2.0) << '\n';
}


copysign(1.0,+2.0) = +1
copysign(1.0,-2.0) = -1
copysign(inf,-2.0) = -inf
copysign(NaN,-2.0) = -nan


abs(float)
fabs
fabsf absolute value of a floating point value (\(\small{|x|}\)|x|)
fabsl (function)
(C++11)
(C++11)
signbit checks if the given number is negative
(C++11) (function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.