📄 mmath.c
字号:
#line 238 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"#include "mal_config.h"#include "mmath.h"#include <math.h>extern double sqrt(double x);extern double cbrt(double x);extern double sin(double x);extern double cos(double x);extern double fabs(double x);#ifdef WIN32#ifndef LIBMMATH#define mmath_export extern __declspec(dllimport)#else#define mmath_export extern __declspec(dllexport)#endif#else#define mmath_export extern#endif#define acos_unary(x, z) *z = acos(*x)#define asin_unary(x, z) *z = asin(*x)#define atan_unary(x, z) *z = atan(*x)#define atan2_binary(x, y, z) *z = atan2(*x,*y)#define cos_unary(x, z) *z = cos(*x)#define sin_unary(x, z) *z = sin(*x)#define tan_unary(x, z) *z = tan(*x)#define cosh_unary(x, z) *z = cosh(*x)#define sinh_unary(x, z) *z = sinh(*x)#define tanh_unary(x, z) *z = tanh(*x)#define exp_unary(x, z) *z = exp(*x)#define log_unary(x, z) *z = log(*x)#define log10_unary(x, z) *z = log10(*x)#define pow_binary(x, y, z) *z = pow(*x,*y)#define sqrt_unary(x, z) *z = sqrt(*x)#define ceil_unary(x, z) *z = ((-1.0<*x)&&(*x<0.0))?0.0:ceil(*x)#define fabs_unary(x, z) *z = fabs(*x)#define floor_unary(x, z) *z = floor(*x)#define fmod_binary(x, y, z) *z = fmod(*x,*y)#ifdef _MSC_VER#include <float.h>/* Windows spells these differently */#define isnan(x) _isnan(x)#define finite(x) _finite(x)/* NOTE: HAVE_FPCLASS assumed... */#define fpclass(x) _fpclass(x)#define FP_NINF _FPCLASS_NINF#define FP_PINF _FPCLASS_PINF#else /* !_MSC_VER */#ifdef HAVE_IEEEFP_H#include <ieeefp.h>#endif#endif#if defined(HAVE_FPCLASSIFY) || defined(fpclassify)/* C99 interface: fpclassify */#define MNisinf(x) (fpclassify(x) == FP_INFINITE)#define MNisnan(x) (fpclassify(x) == FP_NAN)#define MNfinite(x) (!MNisinf(x) && !MNisnan(x))#else#define MNisnan(x) isnan(x)#define MNfinite(x) finite(x)#ifdef HAVE_ISINF#define MNisinf(x) isinf(x)#elsestatic intMNisinf(double x){#ifdef HAVE_FPCLASS int cl = fpclass(x); return ((cl == FP_NINF) || (cl == FP_PINF));#else return 0; /* XXX not correct if infinite */#endif /* HAVE_FPCLASS */}#endif /* HAVE_ISINF */#endif /* HAVE_FPCLASSIFY */#include "mal.h"#include "mal_exception.h"mmath_export str math_unary_FINITE(bit *res, dbl *a);mmath_export str math_unary_ISNAN(bit *res, dbl *a);mmath_export str math_unary_ISINF(int *res, dbl *a);#line 362 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"strmath_unary_ACOS(dbl *res , dbl *a ){#ifdef DEBUG printf( "math_unary_ACOS\n");#endif if (*a == dbl_nil) { *res = dbl_nil; } else { errno = 0; acos_unary( a, res ); if (errno == EDOM) throw(MAL, "mmath._ACOS","Negative argument is not allowed"); if (errno == ERANGE) throw(MAL, "mmath._ACOS","Range error"); if (MNisnan(*res)) throw(MAL, "mmath._ACOS","Negative argument is not allowed"); if (!MNfinite(*res)) throw(MAL, "mmath._ACOS","Range error"); } return MAL_SUCCEED;}#line 337 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"#line 362 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"strmath_unary_ASIN(dbl *res , dbl *a ){#ifdef DEBUG printf( "math_unary_ASIN\n");#endif if (*a == dbl_nil) { *res = dbl_nil; } else { errno = 0; asin_unary( a, res ); if (errno == EDOM) throw(MAL, "mmath._ASIN","Negative argument is not allowed"); if (errno == ERANGE) throw(MAL, "mmath._ASIN","Range error"); if (MNisnan(*res)) throw(MAL, "mmath._ASIN","Negative argument is not allowed"); if (!MNfinite(*res)) throw(MAL, "mmath._ASIN","Range error"); } return MAL_SUCCEED;}#line 338 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"#line 362 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"strmath_unary_ATAN(dbl *res , dbl *a ){#ifdef DEBUG printf( "math_unary_ATAN\n");#endif if (*a == dbl_nil) { *res = dbl_nil; } else { errno = 0; atan_unary( a, res ); if (errno == EDOM) throw(MAL, "mmath._ATAN","Negative argument is not allowed"); if (errno == ERANGE) throw(MAL, "mmath._ATAN","Range error"); if (MNisnan(*res)) throw(MAL, "mmath._ATAN","Negative argument is not allowed"); if (!MNfinite(*res)) throw(MAL, "mmath._ATAN","Range error"); } return MAL_SUCCEED;}#line 339 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"#line 387 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"strmath_binary_ATAN2(dbl *res, dbl *a, dbl *b ){#ifdef DEBUG printf( "math_binary_ATAN2\n");#endif if (*a == dbl_nil || *b == dbl_nil) { *res = dbl_nil; } else { atan2_binary( a, b, res); } return MAL_SUCCEED;}#line 340 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"#line 362 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"strmath_unary_COS(dbl *res , dbl *a ){#ifdef DEBUG printf( "math_unary_COS\n");#endif if (*a == dbl_nil) { *res = dbl_nil; } else { errno = 0; cos_unary( a, res ); if (errno == EDOM) throw(MAL, "mmath._COS","Negative argument is not allowed"); if (errno == ERANGE) throw(MAL, "mmath._COS","Range error"); if (MNisnan(*res)) throw(MAL, "mmath._COS","Negative argument is not allowed"); if (!MNfinite(*res)) throw(MAL, "mmath._COS","Range error"); } return MAL_SUCCEED;}#line 341 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"#line 362 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"strmath_unary_SIN(dbl *res , dbl *a ){#ifdef DEBUG printf( "math_unary_SIN\n");#endif if (*a == dbl_nil) { *res = dbl_nil; } else { errno = 0; sin_unary( a, res ); if (errno == EDOM) throw(MAL, "mmath._SIN","Negative argument is not allowed"); if (errno == ERANGE) throw(MAL, "mmath._SIN","Range error"); if (MNisnan(*res)) throw(MAL, "mmath._SIN","Negative argument is not allowed"); if (!MNfinite(*res)) throw(MAL, "mmath._SIN","Range error"); } return MAL_SUCCEED;}#line 342 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"#line 362 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"strmath_unary_TAN(dbl *res , dbl *a ){#ifdef DEBUG printf( "math_unary_TAN\n");#endif if (*a == dbl_nil) { *res = dbl_nil; } else { errno = 0; tan_unary( a, res ); if (errno == EDOM) throw(MAL, "mmath._TAN","Negative argument is not allowed"); if (errno == ERANGE) throw(MAL, "mmath._TAN","Range error"); if (MNisnan(*res)) throw(MAL, "mmath._TAN","Negative argument is not allowed"); if (!MNfinite(*res)) throw(MAL, "mmath._TAN","Range error"); } return MAL_SUCCEED;}#line 343 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"#line 362 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"strmath_unary_COSH(dbl *res , dbl *a ){#ifdef DEBUG printf( "math_unary_COSH\n");#endif if (*a == dbl_nil) { *res = dbl_nil; } else { errno = 0; cosh_unary( a, res ); if (errno == EDOM) throw(MAL, "mmath._COSH","Negative argument is not allowed"); if (errno == ERANGE) throw(MAL, "mmath._COSH","Range error"); if (MNisnan(*res)) throw(MAL, "mmath._COSH","Negative argument is not allowed"); if (!MNfinite(*res)) throw(MAL, "mmath._COSH","Range error"); } return MAL_SUCCEED;}#line 345 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"#line 362 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"strmath_unary_SINH(dbl *res , dbl *a ){#ifdef DEBUG printf( "math_unary_SINH\n");#endif if (*a == dbl_nil) { *res = dbl_nil; } else { errno = 0; sinh_unary( a, res ); if (errno == EDOM) throw(MAL, "mmath._SINH","Negative argument is not allowed"); if (errno == ERANGE) throw(MAL, "mmath._SINH","Range error"); if (MNisnan(*res)) throw(MAL, "mmath._SINH","Negative argument is not allowed"); if (!MNfinite(*res)) throw(MAL, "mmath._SINH","Range error"); } return MAL_SUCCEED;}#line 346 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"#line 362 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"strmath_unary_TANH(dbl *res , dbl *a ){#ifdef DEBUG printf( "math_unary_TANH\n");#endif if (*a == dbl_nil) { *res = dbl_nil; } else { errno = 0; tanh_unary( a, res ); if (errno == EDOM) throw(MAL, "mmath._TANH","Negative argument is not allowed"); if (errno == ERANGE) throw(MAL, "mmath._TANH","Range error"); if (MNisnan(*res)) throw(MAL, "mmath._TANH","Negative argument is not allowed"); if (!MNfinite(*res)) throw(MAL, "mmath._TANH","Range error"); } return MAL_SUCCEED;}#line 347 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"#line 362 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"strmath_unary_EXP(dbl *res , dbl *a ){#ifdef DEBUG printf( "math_unary_EXP\n");#endif if (*a == dbl_nil) { *res = dbl_nil; } else { errno = 0; exp_unary( a, res ); if (errno == EDOM) throw(MAL, "mmath._EXP","Negative argument is not allowed"); if (errno == ERANGE) throw(MAL, "mmath._EXP","Range error"); if (MNisnan(*res)) throw(MAL, "mmath._EXP","Negative argument is not allowed"); if (!MNfinite(*res)) throw(MAL, "mmath._EXP","Range error"); } return MAL_SUCCEED;}#line 349 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"#line 362 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"strmath_unary_LOG(dbl *res , dbl *a ){#ifdef DEBUG printf( "math_unary_LOG\n");#endif if (*a == dbl_nil) { *res = dbl_nil; } else { errno = 0; log_unary( a, res ); if (errno == EDOM) throw(MAL, "mmath._LOG","Negative argument is not allowed"); if (errno == ERANGE) throw(MAL, "mmath._LOG","Range error"); if (MNisnan(*res)) throw(MAL, "mmath._LOG","Negative argument is not allowed"); if (!MNfinite(*res)) throw(MAL, "mmath._LOG","Range error"); } return MAL_SUCCEED;}#line 350 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"#line 362 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"strmath_unary_LOG10(dbl *res , dbl *a ){#ifdef DEBUG printf( "math_unary_LOG10\n");#endif if (*a == dbl_nil) { *res = dbl_nil; } else { errno = 0; log10_unary( a, res ); if (errno == EDOM) throw(MAL, "mmath._LOG10","Negative argument is not allowed"); if (errno == ERANGE) throw(MAL, "mmath._LOG10","Range error"); if (MNisnan(*res)) throw(MAL, "mmath._LOG10","Negative argument is not allowed"); if (!MNfinite(*res)) throw(MAL, "mmath._LOG10","Range error"); } return MAL_SUCCEED;}#line 351 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"#line 387 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"strmath_binary_POW(dbl *res, dbl *a, dbl *b ){#ifdef DEBUG printf( "math_binary_POW\n");#endif if (*a == dbl_nil || *b == dbl_nil) { *res = dbl_nil; } else { pow_binary( a, b, res); } return MAL_SUCCEED;}#line 353 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"#line 362 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"strmath_unary_SQRT(dbl *res , dbl *a ){#ifdef DEBUG printf( "math_unary_SQRT\n");#endif if (*a == dbl_nil) { *res = dbl_nil; } else { errno = 0; sqrt_unary( a, res ); if (errno == EDOM) throw(MAL, "mmath._SQRT","Negative argument is not allowed"); if (errno == ERANGE) throw(MAL, "mmath._SQRT","Range error"); if (MNisnan(*res)) throw(MAL, "mmath._SQRT","Negative argument is not allowed"); if (!MNfinite(*res)) throw(MAL, "mmath._SQRT","Range error"); } return MAL_SUCCEED;}#line 354 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"#line 362 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"strmath_unary_CEIL(dbl *res , dbl *a ){#ifdef DEBUG printf( "math_unary_CEIL\n");#endif if (*a == dbl_nil) { *res = dbl_nil; } else { errno = 0; ceil_unary( a, res ); if (errno == EDOM) throw(MAL, "mmath._CEIL","Negative argument is not allowed"); if (errno == ERANGE) throw(MAL, "mmath._CEIL","Range error"); if (MNisnan(*res)) throw(MAL, "mmath._CEIL","Negative argument is not allowed"); if (!MNfinite(*res)) throw(MAL, "mmath._CEIL","Range error"); } return MAL_SUCCEED;}#line 356 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"#line 362 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"strmath_unary_FABS(dbl *res , dbl *a ){#ifdef DEBUG printf( "math_unary_FABS\n");#endif if (*a == dbl_nil) { *res = dbl_nil; } else { errno = 0; fabs_unary( a, res ); if (errno == EDOM) throw(MAL, "mmath._FABS","Negative argument is not allowed"); if (errno == ERANGE) throw(MAL, "mmath._FABS","Range error"); if (MNisnan(*res)) throw(MAL, "mmath._FABS","Negative argument is not allowed"); if (!MNfinite(*res)) throw(MAL, "mmath._FABS","Range error"); } return MAL_SUCCEED;}#line 357 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"#line 362 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/kernel/mmath.mx"strmath_unary_FLOOR(dbl *res , dbl *a ){#ifdef DEBUG printf( "math_unary_FLOOR\n");#endif if (*a == dbl_nil) { *res = dbl_nil; } else { errno = 0; floor_unary( a, res ); if (errno == EDOM) throw(MAL, "mmath._FLOOR","Negative argument is not allowed"); if (errno == ERANGE) throw(MAL, "mmath._FLOOR","Range error"); if (MNisnan(*res)) throw(MAL, "mmath._FLOOR","Negative argument is not allowed"); if (!MNfinite(*res))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -