POK
Main Page
Classes
Files
File List
File Members
nextafterf.c
1
/*
2
* POK header
3
*
4
* The following file is a part of the POK project. Any modification should
5
* made according to the POK licence. You CANNOT use this file or a part of
6
* this file is this part of a file for your own project
7
*
8
* For more information on the POK licence, please see our LICENCE FILE
9
*
10
* Please follow the coding guidelines described in doc/CODING_GUIDELINES
11
*
12
* Copyright (c) 2007-2009 POK team
13
*
14
* Created by julien on Fri Jan 30 14:41:34 2009
15
*/
16
17
/* s_nextafterf.c -- float version of s_nextafter.c.
18
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
19
*/
20
21
/*
22
* ====================================================
23
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
24
*
25
* Developed at SunPro, a Sun Microsystems, Inc. business.
26
* Permission to use, copy, modify, and distribute this
27
* software is freely granted, provided that this notice
28
* is preserved.
29
* ====================================================
30
*/
31
32
#ifdef POK_NEEDS_LIBMATH
33
34
#include <libm.h>
35
#include "math_private.h"
36
37
float
38
nextafterf(
float
x,
float
y)
39
{
40
int32_t hx,hy,ix,iy;
41
42
GET_FLOAT_WORD(hx,x);
43
GET_FLOAT_WORD(hy,y);
44
ix = hx&0x7fffffff;
/* |x| */
45
iy = hy&0x7fffffff;
/* |y| */
46
47
if
((ix>0x7f800000) ||
/* x is nan */
48
(iy>0x7f800000))
/* y is nan */
49
return
x+y;
50
if
(x==y)
return
x;
/* x=y, return x */
51
if
(ix==0) {
/* x == 0 */
52
SET_FLOAT_WORD(x,(hy&0x80000000)|1);
/* return +-minsubnormal */
53
y = x*x;
54
if
(y==x)
return
y;
else
return
x;
/* raise underflow flag */
55
}
56
if
(hx>=0) {
/* x > 0 */
57
if
(hx>hy) {
/* x > y, x -= ulp */
58
hx -= 1;
59
}
else
{
/* x < y, x += ulp */
60
hx += 1;
61
}
62
}
else
{
/* x < 0 */
63
if
(hy>=0||hx>hy){
/* x < y, x -= ulp */
64
hx -= 1;
65
}
else
{
/* x > y, x += ulp */
66
hx += 1;
67
}
68
}
69
hy = hx&0x7f800000;
70
if
(hy>=0x7f800000)
return
x+x;
/* overflow */
71
if
(hy<0x00800000) {
/* underflow */
72
y = x*x;
73
if
(y!=x) {
/* raise underflow flag */
74
SET_FLOAT_WORD(y,hx);
75
return
y;
76
}
77
}
78
SET_FLOAT_WORD(x,hx);
79
return
x;
80
}
81
82
#endif
libpok
libm
nextafterf.c
Generated on Fri Jun 1 2012 19:07:13 for POK by
1.8.1