Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 83932dc9 in mainline


Ignore:
Timestamp:
2018-09-12T16:51:07Z (3 years ago)
Author:
Jiří Zárevúcky <jiri.zarevucky@…>
Branches:
lfn, master
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)
Message:

Split up libmath functions into more files

so that they don't conflict with fdlibm during static linking.

Location:
uspace/lib/math
Files:
5 added
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/math/Makefile

    rec9aadd r83932dc9  
    3939        generic/fabs.c \
    4040        generic/fmod.c \
     41        generic/fmodf.c \
    4142        generic/nearbyint.c \
    4243        generic/round.c \
    4344        generic/trig.c \
     45        generic/sin.c \
     46        generic/cos.c \
     47        generic/sincos.c \
    4448        generic/trunc.c
    4549
  • uspace/lib/math/generic/fmod.c

    rec9aadd r83932dc9  
    3535#include <math.h>
    3636
    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 uses
    42  * division and multiplication (instead of exact
    43  * arithmetics). Thus the result might be very
    44  * imprecise (depending on the magnitude of the
    45  * 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 arithmetics
    56 
    57         float quotient = truncf(dividend / divisor);
    58 
    59         return (dividend - quotient * divisor);
    60 }
    61 
    6237/** Remainder function (64-bit floating point)
    6338 *
  • uspace/lib/math/generic/trig.c

    rec9aadd r83932dc9  
    3535
    3636#include <math.h>
     37#include "internal.h"
    3738
    3839#define TAYLOR_DEGREE_32 13
     
    175176 *
    176177 */
    177 static float base_sin_32(float arg)
     178float __math_base_sin_32(float arg)
    178179{
    179180        unsigned int period = arg / (M_PI / 4);
     
    208209 *
    209210 */
    210 static double base_sin_64(double arg)
     211double __math_base_sin_64(double arg)
    211212{
    212213        unsigned int period = arg / (M_PI / 4);
     
    241242 *
    242243 */
    243 static float base_cos_32(float arg)
     244float __math_base_cos_32(float arg)
    244245{
    245246        unsigned int period = arg / (M_PI / 4);
     
    274275 *
    275276 */
    276 static double base_cos_64(double arg)
     277double __math_base_cos_64(double arg)
    277278{
    278279        unsigned int period = arg / (M_PI / 4);
     
    295296}
    296297
    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 than
    375  * 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 than
    396  * 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 
    415298/** @}
    416299 */
Note: See TracChangeset for help on using the changeset viewer.