Mercurial > hg > octave-nkf
comparison liboctave/lo-mappers.cc @ 7740:39930366b709
implement builtin log2
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 30 Apr 2008 03:30:34 -0400 |
parents | 446dec9d1de5 |
children | 82be108cc558 |
comparison
equal
deleted
inserted
replaced
7739:ca9bfe159144 | 7740:39930366b709 |
---|---|
137 return log2 (x); | 137 return log2 (x); |
138 #else | 138 #else |
139 #if defined (M_LN2) | 139 #if defined (M_LN2) |
140 static double ln2 = M_LN2; | 140 static double ln2 = M_LN2; |
141 #else | 141 #else |
142 static double ln2 = log2 (2); | 142 static double ln2 = log (2); |
143 #endif | 143 #endif |
144 | 144 |
145 return log (x) / ln2; | 145 return log (x) / ln2; |
146 #endif | 146 #endif |
147 } | |
148 | |
149 Complex | |
150 xlog2 (const Complex& x) | |
151 { | |
152 #if defined (M_LN2) | |
153 static double ln2 = M_LN2; | |
154 #else | |
155 static double ln2 = log (2); | |
156 #endif | |
157 | |
158 return std::log (x) / ln2; | |
147 } | 159 } |
148 | 160 |
149 double | 161 double |
150 xexp2 (double x) | 162 xexp2 (double x) |
151 { | 163 { |
153 return exp2 (x); | 165 return exp2 (x); |
154 #else | 166 #else |
155 #if defined (M_LN2) | 167 #if defined (M_LN2) |
156 static double ln2 = M_LN2; | 168 static double ln2 = M_LN2; |
157 #else | 169 #else |
158 static double ln2 = log2 (2); | 170 static double ln2 = log (2); |
159 #endif | 171 #endif |
160 | 172 |
161 return exp (x * ln2); | 173 return exp (x * ln2); |
162 #endif | 174 #endif |
175 } | |
176 | |
177 double | |
178 xlog2 (double x, int& exp) | |
179 { | |
180 return frexp (x, &exp); | |
181 } | |
182 | |
183 Complex | |
184 xlog2 (const Complex& x, int& exp) | |
185 { | |
186 double ax = std::abs (x); | |
187 double lax = xlog2 (ax, exp); | |
188 return (exp == 0) ? x : (x / ax) * lax; | |
163 } | 189 } |
164 | 190 |
165 // double -> bool mappers. | 191 // double -> bool mappers. |
166 | 192 |
167 bool | 193 bool |