File: s_nearbyint.c

package info (click to toggle)
picolibc 1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 31,616 kB
  • sloc: ansic: 312,308; asm: 22,739; perl: 2,414; sh: 1,619; python: 1,019; pascal: 329; exp: 287; makefile: 164; xml: 40; cpp: 10
file content (71 lines) | stat: -rw-r--r-- 1,881 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * ====================================================
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
 *
 * Developed at SunPro, a Sun Microsystems, Inc. business.
 * Permission to use, copy, modify, and distribute this
 * software is freely granted, provided that this notice
 * is preserved.
 * ====================================================
 */
/*
FUNCTION
<<nearbyint>>, <<nearbyintf>>---round to integer
INDEX
	nearbyint
INDEX
	nearbyintf

SYNOPSIS
	#include <math.h>
	double nearbyint(double <[x]>);
	float nearbyintf(float <[x]>);

DESCRIPTION
The <<nearbyint>> functions round their argument to an integer value in
floating-point format, using the current rounding direction and
(supposedly) without raising the "inexact" floating-point exception.
See the <<rint>> functions for the same function with the "inexact"
floating-point exception being raised when appropriate.

BUGS
Newlib does not support the floating-point exception model, so that
the floating-point exception control is not present and thereby what may
be seen will be compiler and hardware dependent in this regard.
The Newlib <<nearbyint>> functions are identical to the <<rint>>
functions with respect to the floating-point exception behavior, and
will cause the "inexact" exception to be raised for most targets.

RETURNS
<[x]> rounded to an integral value, using the current rounding direction.

PORTABILITY
ANSI C, POSIX

SEEALSO
<<rint>>, <<round>>
*/

#include <math.h>
#include "fdlibm.h"

#ifdef _NEED_FLOAT64

__float64
nearbyint64(__float64 x)
{
    if (isnan(x)) return x + x;
#if defined(FE_INEXACT) && !defined(PICOLIBC_DOUBLE_NOEXECPT)
    fenv_t env;
    fegetenv(&env);
#endif
    x = rint64(x);
#if defined(FE_INEXACT) && !defined(PICOLIBC_DOUBLE_NOEXECPT)
    fesetenv(&env);
#endif
    return x;
}

_MATH_ALIAS_d_d(nearbyint)

#endif /* _NEED_FLOAT64 */