lrint(), lrintf(), lrintl() and llrint(), llrintf(), llrintl() -- Round the argument to the nearest

lrint(), lrintf(), lrintl() and llrint(), llrintf(), llrintl() -- Round the argument to the nearest integer

z/OS V1R12.0 XL C/C++ Run-Time Library Reference
SA22-7821-12 

Standards

Standards / Extensions C or C++ Dependencies
C99
Single UNIX® Specification, Version 3
C++ TR1 C99
both  z/OS V1R7

Format

#define _ISOC99_SOURCE
#include <math.h>

long int lrint(double x);
long int lrintf(float x);
long int lrintl(long double x);

long long int llrint(double x);
long long int llrintf(float x);
long long int llrintl(long double x);

C++ TR1 C99:

#define _TR1_C99
#include <math.h>

long int lrint(float x);
long int lrint(long double x);
long long int llrint(float x);
long long int llrint(long double x);
Compile requirement:
The llrint() family of functions requires the long long data type. See  z/OS XL C/C++ Language Reference for information on how to make long long available.

General description

The lrint() and llrint() families of functions round their argument to the nearest integer value according to the current rounding mode. If the rounded value is outside the range of the return type, the numeric result is unspecified. A range error may occur if the magnitude of x is too large.

Note:
The following table shows the viable formats for these functions. See  IEEE binary floating-point for more information about IEEE Binary Floating-Point.
Function Hex IEEE
lrint X X
lrintf X X
lrintl X X
llrint X X
llrintf X X
llrintl X X

Returned value

If successful, they return the rounded integer value. If the correct value is positive or negative and too large to represent as a long (lrint() family) or long long (llrint() family), a domain error will occur and an unspecified value is returned.

Example

/*
 * This program illustrates the use of lrint() function
 *
 * Note: To get the output shown in this  information, this program 
 *       should be compiled using FLOAT(IEEE)
 *
 */
#define _ISOC99_SOURCE
#include <math.h>
#include <stdio.h>
#include <_Ieee754.h>   /* save/get fpc functions   */

char *RoundStr (_FP_rmode_t rm_type) {
  char *RndStr="undetermined";
   switch (rm_type) {
     case (_RMODE_RN):
        RndStr="round to nearest";
        break;
     case (_RMODE_RZ):
        RndStr="round toward zero";
        break;
     case (_RMODE_RP):
        RndStr="round toward +infinity ";
        break;
     case (_RMODE_RM):
        RndStr="round toward -infinity ";
        break;
   }
   return (RndStr);
}

void main() {

  _FP_fpcreg_t save_rmode, current_rmode;
  long int     rnd2nearest;
  double       number=500.99;

  printf("Illustrates the lrint() function\n");
  __fpc_rd(&current_rmode);     /* get current rounding mode */

  rnd2nearest = lrint(number);
  printf ("When rounding direction is %s:\n lrint(%.2f) = %li\n",RoundStr(current_rmode.rmode), number, rnd2nearest);
  save_rmode.rmode = _RMODE_RZ;
  __fpc_sm(save_rmode.rmode);   /* set rounding mode to round to zero */

  rnd2nearest = lrint(number);
  printf ("When rounding direction is %s:\n lrint(%.2f) = %li\n",RoundStr(save_rmode.rmode), number, rnd2nearest);
}

Output

Illustrates the lrint() function
When rounding direction is round to nearest:
 lrint(500.99) = 501
When rounding direction is round toward zero:
 lrint(500.99) = 500

Related information

http://pic.dhe.ibm.com/infocenter/zos/v1r12/index.jsp?topic=%2Fcom.ibm.zos.r12.bpxbd00%2Flrint.htm

http://www.cplusplus.com/reference/cmath/lrint/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值