c语言 函数的参数传递示例_C ++中带示例的signbit()函数

本文详细介绍了C++中的signbit()函数,该函数用于检查浮点数的符号。文章通过实例展示了如何使用signbit()函数判断一个数是否为负,并提供了C++代码示例。了解signbit()函数对于C++编程中的数值运算处理非常有帮助。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

c语言 函数的参数传递示例

C ++ signbit()函数 (C++ signbit() function)

signbit() function is a library function of cmath header. It is used to check the sign of the given value. It accepts a parameter (float, double or long double) and returns 1 if the given value is negative; 0, otherwise.

signbit()函数cmath标头的库函数。 用于检查给定值的符号。 它接受一个参数( float , double或long double ),如果给定的值为负,则返回1;否则返回10 ,否则。

Syntax of signbit() function:

signbit()函数的语法:

In C99, it has been implemented as a macro,

在C99中,它已实现为宏,

    signbit(x)

In C++11, it has been implemented as a function,

在C ++ 11中,它已作为函数实现,

    bool signbit (float x);
    bool signbit (double x);
    bool signbit (long double x);

Parameter(s):

参数:

  • x – represents the value to check its sign.

    x –表示检查其符号的值。

Return value:

返回值:

It returns 1 if x is negative; 0, otherwise.

如果x为负,则返回1;否则为0。 0,否则。

Example:

例:

    Input:
    double x = 10.0;
    
    Function call:
    signbit(x);
    
    Output:
    0

    Input:
    double x = -10.0;
    
    Function call:
    signbit(x);
    
    Output:
    1

C ++代码演示signbit()函数的示例 (C++ code to demonstrate the example of signbit() function)

// C++ code to demonstrate the example of
// signbit() function

#include <iostream>
#include <cmath>
using namespace std;

// main() section
int main()
{
    double x = 0.0;

    x = 10.0;
    cout << "signbit(" << x << "): " << signbit(x) << endl;

    x = -10.0;
    cout << "signbit(" << x << "): " << signbit(x) << endl;

    x = 10.10;
    cout << "signbit(" << x << "): " << signbit(x) << endl;

    x = -10.10;
    cout << "signbit(" << x << "): " << signbit(x) << endl;

    x = 0.0;
    cout << "signbit(" << x << "): " << signbit(x) << endl;

    x = -10.0 / 2.5;
    cout << "signbit(" << x << "): " << signbit(x) << endl;

    x = 10.0 / -2.5;
    cout << "signbit(" << x << "): " << signbit(x) << endl;

    x = sqrt(-1);
    cout << "signbit(" << x << "): " << signbit(x) << endl;

    return 0;
}

Output

输出量

signbit(10): 0
signbit(-10): 1
signbit(10.1): 0
signbit(-10.1): 1
signbit(0): 0
signbit(-4): 1
signbit(-4): 1
signbit(-nan): 1

Reference: C++ signbit() function

参考: C ++ signbit()函数

翻译自: https://www.includehelp.com/cpp-tutorial/signbit-function-with-example.aspx

c语言 函数的参数传递示例

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值