Changeset 83932dc9 in mainline
- Timestamp:
- 2018-09-12T16:51:07Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b2aaaa0
- Parents:
- ec9aadd
- git-author:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-09-12 16:50:02)
- git-committer:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-09-12 16:51:07)
- Location:
- uspace/lib/math
- Files:
-
- 5 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/math/Makefile
rec9aadd r83932dc9 39 39 generic/fabs.c \ 40 40 generic/fmod.c \ 41 generic/fmodf.c \ 41 42 generic/nearbyint.c \ 42 43 generic/round.c \ 43 44 generic/trig.c \ 45 generic/sin.c \ 46 generic/cos.c \ 47 generic/sincos.c \ 44 48 generic/trunc.c 45 49 -
uspace/lib/math/generic/fmod.c
rec9aadd r83932dc9 35 35 #include <math.h> 36 36 37 /** Remainder function (32-bit floating point)38 *39 * Calculate the modulo of dividend by divisor.40 *41 * This is a very basic implementation that uses42 * division and multiplication (instead of exact43 * arithmetics). Thus the result might be very44 * imprecise (depending on the magnitude of the45 * arguments).46 *47 * @param dividend Dividend.48 * @param divisor Divisor.49 *50 * @return Modulo.51 *52 */53 float fmodf(float dividend, float divisor)54 {55 // FIXME: replace with exact arithmetics56 57 float quotient = truncf(dividend / divisor);58 59 return (dividend - quotient * divisor);60 }61 62 37 /** Remainder function (64-bit floating point) 63 38 * -
uspace/lib/math/generic/trig.c
rec9aadd r83932dc9 35 35 36 36 #include <math.h> 37 #include "internal.h" 37 38 38 39 #define TAYLOR_DEGREE_32 13 … … 175 176 * 176 177 */ 177 static floatbase_sin_32(float arg)178 float __math_base_sin_32(float arg) 178 179 { 179 180 unsigned int period = arg / (M_PI / 4); … … 208 209 * 209 210 */ 210 static doublebase_sin_64(double arg)211 double __math_base_sin_64(double arg) 211 212 { 212 213 unsigned int period = arg / (M_PI / 4); … … 241 242 * 242 243 */ 243 static floatbase_cos_32(float arg)244 float __math_base_cos_32(float arg) 244 245 { 245 246 unsigned int period = arg / (M_PI / 4); … … 274 275 * 275 276 */ 276 static doublebase_cos_64(double arg)277 double __math_base_cos_64(double arg) 277 278 { 278 279 unsigned int period = arg / (M_PI / 4); … … 295 296 } 296 297 297 /** Sine (32-bit floating point)298 *299 * Compute sine value.300 *301 * @param arg Sine argument.302 *303 * @return Sine value.304 *305 */306 float sinf(float arg)307 {308 float base_arg = fmodf(arg, 2 * M_PI);309 310 if (base_arg < 0)311 return -base_sin_32(-base_arg);312 313 return base_sin_32(base_arg);314 }315 316 /** Sine (64-bit floating point)317 *318 * Compute sine value.319 *320 * @param arg Sine argument.321 *322 * @return Sine value.323 *324 */325 double sin(double arg)326 {327 double base_arg = fmod(arg, 2 * M_PI);328 329 if (base_arg < 0)330 return -base_sin_64(-base_arg);331 332 return base_sin_64(base_arg);333 }334 335 /** Cosine (32-bit floating point)336 *337 * Compute cosine value.338 *339 * @param arg Cosine argument.340 *341 * @return Cosine value.342 *343 */344 float cosf(float arg)345 {346 float base_arg = fmodf(arg, 2 * M_PI);347 348 if (base_arg < 0)349 return base_cos_32(-base_arg);350 351 return base_cos_32(base_arg);352 }353 354 /** Cosine (64-bit floating point)355 *356 * Compute cosine value.357 *358 * @param arg Cosine argument.359 *360 * @return Cosine value.361 *362 */363 double cos(double arg)364 {365 double base_arg = fmod(arg, 2 * M_PI);366 367 if (base_arg < 0)368 return base_cos_64(-base_arg);369 370 return base_cos_64(base_arg);371 }372 373 /**374 * Computes sine and cosine at the same time, which might be more efficient than375 * computing each separately.376 *377 * @param x Input value.378 * @param s Output sine value, *s = sinf(x).379 * @param c Output cosine value, *c = cosf(x).380 */381 void sincosf(float x, float *s, float *c)382 {383 float base_arg = fmodf(x, 2 * M_PI);384 385 if (base_arg < 0) {386 *s = -base_sin_32(-base_arg);387 *c = base_cos_32(-base_arg);388 } else {389 *s = base_sin_32(base_arg);390 *c = base_cos_32(base_arg);391 }392 }393 394 /**395 * Computes sine and cosine at the same time, which might be more efficient than396 * computing each separately.397 *398 * @param x Input value.399 * @param s Output sine value, *s = sin(x).400 * @param c Output cosine value, *c = cos(x).401 */402 void sincos(double x, double *s, double *c)403 {404 double base_arg = fmod(x, 2 * M_PI);405 406 if (base_arg < 0) {407 *s = -base_sin_64(-base_arg);408 *c = base_cos_64(-base_arg);409 } else {410 *s = base_sin_64(base_arg);411 *c = base_cos_64(base_arg);412 }413 }414 415 298 /** @} 416 299 */
Note:
See TracChangeset
for help on using the changeset viewer.