POK
fpclassify.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 Sat Jan 31 15:49:24 2009
15  */
16 
17 #ifdef POK_NEEDS_LIBMATH
18 
19 #include <libm.h>
20 #include <types.h>
21 #include "math_private.h"
22 
23 int
24 __fpclassifyf (float x)
25 {
26  uint32_t w;
27 
28  GET_FLOAT_WORD(w,x);
29 
30  if (w == 0x00000000 || w == 0x80000000)
31  return FP_ZERO;
32  else if ((w >= 0x00800000 && w <= 0x7f7fffff) ||
33  (w >= 0x80800000 && w <= 0xff7fffff))
34  return FP_NORMAL;
35  else if ((w >= 0x00000001 && w <= 0x007fffff) ||
36  (w >= 0x80000001 && w <= 0x807fffff))
37  return FP_SUBNORMAL;
38  else if (w == 0x7f800000 || w == 0xff800000)
39  return FP_INFINITE;
40  else
41  return FP_NAN;
42 }
43 
44 int
45 __fpclassifyd (double x)
46 {
47  uint32_t msw, lsw;
48 
49  EXTRACT_WORDS(msw,lsw,x);
50 
51  if ((msw == 0x00000000 && lsw == 0x00000000) ||
52  (msw == 0x80000000 && lsw == 0x00000000))
53  return FP_ZERO;
54  else if ((msw >= 0x00100000 && msw <= 0x7fefffff) ||
55  (msw >= 0x80100000 && msw <= 0xffefffff))
56  return FP_NORMAL;
57  /*
58  else if ((msw >= 0x00000000 && msw <= 0x000fffff) ||
59 bugfix : msw is an uint32_t (unsigned) value, always positive
60  */
61  else if ((msw <= 0x000fffff) ||
62  (msw >= 0x80000000 && msw <= 0x800fffff))
63  /* zero is already handled above */
64  return FP_SUBNORMAL;
65  else if ((msw == 0x7ff00000 && lsw == 0x00000000) ||
66  (msw == 0xfff00000 && lsw == 0x00000000))
67  return FP_INFINITE;
68  else
69  return FP_NAN;
70 }
71 
72 
73 #endif