3a2e272dae8980932f8ee9ea8abbc7ccb8fc941c
[o-du/l2.git] / src / cm / cm_math.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18 \f
19
20 /********************************************************************20**
21
22      Name:     common MATH library functions
23   
24      Type:     C source file
25   
26      Desc:     Common functions that are implemented in
27                a portable manner. These functions are selected 
28                based on the operating system.
29
30      File:     cm_math.c
31
32 *********************************************************************21*/
33
34
35 /* header include files (.h) */
36 #include "envopt.h"             /* environment options */
37 #include "envdep.h"             /* environment dependent */
38 #include "envind.h"             /* environment independent */
39 #include "gen.h"                /* general */
40 #include "ssi.h"                /* system services interface */
41
42 #include "cm_math.h"
43 #include "cm_math.x"
44
45 #include <stdlib.h>
46
47 #include <math.h>
48
49
50 #ifdef SS_FLOAT
51 /*
52 *
53 *       Fun:   cmAbs
54 *
55 *       Desc:  common primitive for an absolute value of an integer
56 *
57 *       Ret:   absolute value of the operand 
58 *
59 *       Notes: None
60 *
61 *       File:  cm_math.c
62 *
63 */
64 uint32_t cmAbs(F64  val)
65 {
66 #if (defined(SUNOS)|| defined(WIN32)|| defined(WIN2K)|| defined (SS_LINUX))
67    return ((uint32_t) abs((int) val));/* G++ */
68 #endif
69 } /* end of cmAbs */
70 #endif /* SS_FLOAT */
71
72
73 #ifdef SS_FLOAT
74 /*
75 *
76 *       Fun:   cmPow
77 *
78 *       Desc:  common primitive for computing the power of x raised to y.
79 *
80 *       Ret:   value of x raised to the power of y.
81 *
82 *       Notes: None
83 *
84 *       File:  cm_math.c
85 *
86 */
87 F64 cmPow(F64 x,F64 y)
88 {
89 #if (defined(SUNOS)|| defined(WIN32)|| defined(WIN2K)|| defined (SS_LINUX))
90    return ((F64) pow((F64)x, (F64)y));
91 #endif
92 } /* end of cmPow */
93 #endif /* SS_FLOAT */
94
95 #ifdef SS_FLOAT
96 /*
97 *
98 *       Fun:   cmFloor
99 *
100 *       Desc:  common primitive for computing the largest integral value 
101 *              not greater than x.
102 *
103 *       Ret:   floor value of x 
104 *
105 *       Notes: None
106 *
107 *       File:  cm_math.c
108 *
109 */
110 F64 cmFloor(F64  x)
111 {
112 #if (defined(SUNOS)|| defined(WIN32)|| defined(WIN2K)|| defined (SS_LINUX))
113    return ((F64) floor((F64)x));
114 #endif
115
116 } /* end of cmFloor */
117 #endif /* SS_FLOAT */
118
119 #ifdef SS_FLOAT
120 /*
121 *
122 *       Fun:   cmLog
123 *
124 *       Desc:  common primitive for computing the natural logrithm of x.
125 *
126 *       Ret:   loge(x)
127 *
128 *       Notes: None
129 *
130 *       File:  cm_math.c
131 *
132 */
133 F64 cmLog(F64 x)
134 {
135 #if (defined(SUNOS)|| defined(WIN32)|| defined(WIN2K)|| defined (SS_LINUX))
136    return ((F64) log((F64)x));
137 #endif
138
139 } /* end of cmLog */
140 #endif /* SS_FLOAT */
141
142 #ifdef SS_FLOAT
143 /*
144 *
145 *       Fun:   cmLog10
146 *
147 *       Desc:  common primitive for computing the base 10 logrithm of x.
148 *
149 *       Ret:   log10(x)
150 *
151 *       Notes: None
152 *
153 *       File:  cm_math.c
154 *
155 */
156 F64 cmLog10(F64 x)
157 {
158 #if (defined(SUNOS)|| defined(WIN32)|| defined(WIN2K)|| defined (SS_LINUX))
159    return ((F64) log10((F64)x));
160 #endif
161 } /* end of cmLog10 */
162 #endif /* SS_FLOAT */
163
164 /**********************************************************************
165          End of file
166 **********************************************************************/