Debian Codegraph @

share/libc/math.c

raw
1 /**************************************************************************/
2 /* */
3 /* This file is part of Frama-C. */
4 /* */
5 /* Copyright (C) 2007-2022 */
6 /* CEA (Commissariat à l'énergie atomique et aux énergies */
7 /* alternatives) */
8 /* */
9 /* you can redistribute it and/or modify it under the terms of the GNU */
10 /* Lesser General Public License as published by the Free Software */
11 /* Foundation, version 2.1. */
12 /* */
13 /* It is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16 /* GNU Lesser General Public License for more details. */
17 /* */
18 /* See the GNU Lesser General Public License version 2.1 */
19 /* for more details (enclosed in the file licenses/LGPLv2.1). */
20 /* */
21 /**************************************************************************/
22
23 /* ISO C: 7.12 */
24
25 #include "math.h"
26 __PUSH_FC_STDLIB
27
28 double fabs(double x){
29 if(x==0.0) return 0.0;
30 if (x>0.0) return x;
31 return -x;
32 }
33
34 float fabsf(float x)
35 {
36 if (x == 0.0f) {
37 return 0.0f;
38 } else if (x > 0.0f) {
39 return x;
40 } else {
41 return -x;
42 }
43 }
44
45 int __finitef(float f)
46 {
47 union __fc_u_finitef { float f ; unsigned short w[2] ; } u ;
48 unsigned short usExp ;
49
50 u.f = f ; /* Initilize for word access */
51 usExp = (u.w[1] & 0x7F80) ; /* Isolate the exponent */
52 usExp >>= 7 ; /* Right align */
53
54 /* A floating point value is invalid, if the exponent is 0xff */
55 return !(usExp == 0xff) ;
56 }
57
58 int __finite(double d)
59 {
60 union __fc_u_finite { double d ; unsigned short w[4] ; } u ;
61 unsigned short usExp ;
62
63 u.d = d ; /* Initilize for word access */
64 usExp = (u.w[3] & 0x7F80) ; /* Isolate the exponent */
65 usExp >>= 7 ; /* Right align */
66
67 /* A floating point value is invalid, if the exponent is 0xff */
68 return !(usExp == 0xff) ;
69 }
70
71 __POP_FC_STDLIB