Fixes for incorrect TBS calculation and memory configuration [Issue-ID: ODUHIGH-338]
[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 <stdlib.h>
44 #include <math.h>
45
46 #ifdef SS_FLOAT
47 /*
48 *
49 *       Fun:   cmAbs
50 *
51 *       Desc:  common primitive for an absolute value of an integer
52 *
53 *       Ret:   absolute value of the operand 
54 *
55 *       Notes: None
56 *
57 *       File:  cm_math.c
58 *
59 */
60 uint32_t cmAbs(F64  val)
61 {
62 #if (defined(SUNOS)|| defined(WIN32)|| defined(WIN2K)|| defined (SS_LINUX))
63    return ((uint32_t) abs((int) val));/* G++ */
64 #endif
65 } /* end of cmAbs */
66 #endif /* SS_FLOAT */
67
68
69 #ifdef SS_FLOAT
70 /*
71 *
72 *       Fun:   cmPow
73 *
74 *       Desc:  common primitive for computing the power of x raised to y.
75 *
76 *       Ret:   value of x raised to the power of y.
77 *
78 *       Notes: None
79 *
80 *       File:  cm_math.c
81 *
82 */
83 F64 cmPow(F64 x,F64 y)
84 {
85 #if (defined(SUNOS)|| defined(WIN32)|| defined(WIN2K)|| defined (SS_LINUX))
86    return ((F64) pow((F64)x, (F64)y));
87 #endif
88 } /* end of cmPow */
89 #endif /* SS_FLOAT */
90
91 #ifdef SS_FLOAT
92 /*
93 *
94 *       Fun:   cmFloor
95 *
96 *       Desc:  common primitive for computing the largest integral value 
97 *              not greater than x.
98 *
99 *       Ret:   floor value of x 
100 *
101 *       Notes: None
102 *
103 *       File:  cm_math.c
104 *
105 */
106 F64 cmFloor(F64  x)
107 {
108 #if (defined(SUNOS)|| defined(WIN32)|| defined(WIN2K)|| defined (SS_LINUX))
109    return ((F64) floor((F64)x));
110 #endif
111
112 } /* end of cmFloor */
113 #endif /* SS_FLOAT */
114
115 #ifdef SS_FLOAT
116 /*
117 *
118 *       Fun:   cmLog
119 *
120 *       Desc:  common primitive for computing the natural logrithm of x.
121 *
122 *       Ret:   loge(x)
123 *
124 *       Notes: None
125 *
126 *       File:  cm_math.c
127 *
128 */
129 F64 cmLog(F64 x)
130 {
131 #if (defined(SUNOS)|| defined(WIN32)|| defined(WIN2K)|| defined (SS_LINUX))
132    return ((F64) log((F64)x));
133 #endif
134
135 } /* end of cmLog */
136 #endif /* SS_FLOAT */
137
138 #ifdef SS_FLOAT
139 /*
140 *
141 *       Fun:   cmLog10
142 *
143 *       Desc:  common primitive for computing the base 10 logrithm of x.
144 *
145 *       Ret:   log10(x)
146 *
147 *       Notes: None
148 *
149 *       File:  cm_math.c
150 *
151 */
152 F64 cmLog10(F64 x)
153 {
154 #if (defined(SUNOS)|| defined(WIN32)|| defined(WIN2K)|| defined (SS_LINUX))
155    return ((F64) log10((F64)x));
156 #endif
157 } /* end of cmLog10 */
158 #endif /* SS_FLOAT */
159
160 /*
161 *
162 *       Fun:   cmLog
163 *
164 *       Desc:  common primitive for computing the base 2 logrithm of x.
165 *
166 *       Ret:   log2(x)
167 *
168 *       Notes: None
169 *
170 *       File:  cm_math.c
171 *
172 */
173 float cmLog2(uint32_t x)
174 {
175    return ((float) log2(x));
176 }
177
178 /**********************************************************************
179          End of file
180 **********************************************************************/