博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
lrint函数_C ++中带有示例的lrint()函数
阅读量:2530 次
发布时间:2019-05-11

本文共 2351 字,大约阅读时间需要 7 分钟。

lrint函数

C ++ lrint()函数 (C++ lrint() function)

lrint() function is a library function of cmath header, it is used to round the given value and convert it to a long integer. It accepts a value (float, double, or long double) and returns a long integer value after rounding it based on the rounding direction specified by fegetround() function.

lrint()函数cmath标头的库函数,用于舍入给定值并将其转换为长整数。 它接受一个值( float , double或long double ),并在根据fegetround()函数指定的舍入方向将其舍入后返回一个长整数值。

Syntax of lrint() function:

lrint()函数的语法:

C++11:

C ++ 11:

long int lrint (double x);    long int lrint (float x);    long int lrint (long double x);    long int lrint (T x);

Parameter(s):

参数:

  • x – represents the value to round.

    x –表示要取整的值。

Return value:

返回值:

The returns type of this function is long int, it returns a long integer value rounded to nearby integral.

此函数的返回类型为long int ,它返回一个四舍五入到附近整数的长整数值。

Example:

例:

Input:    float x = 123.4f;        Function call:    lrint(x);        Output:    123    Input:    float x = 123.5f;        Function call:    lrint(x);        Output:    124

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

// C++ code to demonstrate the example of// lrint() function#include 
#include
#include
// for fegetround()using namespace std;int main(){ float x = 0.0f; cout << "Specified rounding is: "; switch (fegetround()) { case FE_DOWNWARD: cout << "Downward" << endl; break; case FE_TONEAREST: cout << "To-nearest" << endl; break; case FE_TOWARDZERO: cout << "Toward-zero" << endl; break; case FE_UPWARD: cout << "Upward" << endl; break; default: cout << "Unknown" << endl; } x = 123.4f; cout << "lrint(" << x << "): " << lrint(x) << endl; x = 123.5f; cout << "lrint(" << x << "): " << lrint(x) << endl; x = 123.6f; cout << "lrint(" << x << "): " << lrint(x) << endl; x = -123.4f; cout << "lrint(" << x << "): " << lrint(x) << endl; x = -123.5f; cout << "lrint(" << x << "): " << lrint(x) << endl; x = -123.6f; cout << "lrint(" << x << "): " << lrint(x) << endl; return 0;}

Output

输出量

Specified rounding is: To-nearestlrint(123.4): 123lrint(123.5): 124lrint(123.6): 124lrint(-123.4): -123lrint(-123.5): -124lrint(-123.6): -124

Reference:

参考:

翻译自:

lrint函数

转载地址:http://mgazd.baihongyu.com/

你可能感兴趣的文章
iOS开发网络篇—XML数据的解析
查看>>
[BZOJ4303]数列
查看>>
一般处理程序在VS2012中打开问题
查看>>
C语言中的++和--
查看>>
thinkphp3.2.3入口文件详解
查看>>
POJ 1141 Brackets Sequence
查看>>
Ubuntu 18.04 root 使用ssh密钥远程登陆
查看>>
Servlet和JSP的异同。
查看>>
虚拟机centOs Linux与Windows之间的文件传输
查看>>
ethereum(以太坊)(二)--合约中属性和行为的访问权限
查看>>
IOS内存管理
查看>>
middle
查看>>
[Bzoj1009][HNOI2008]GT考试(动态规划)
查看>>
Blob(二进制)、byte[]、long、date之间的类型转换
查看>>
OO第一次总结博客
查看>>
day7
查看>>
iphone移动端踩坑
查看>>
vs无法加载项目
查看>>
Beanutils基本用法
查看>>
玉伯的一道课后题题解(关于 IEEE 754 双精度浮点型精度损失)
查看>>