"Fossies" - the Fresh Open Source Software Archive

Member "AutoHotkey_L-1.1.33.09/source/qmath.h" (8 May 2021, 18706 Bytes) of package /windows/misc/AutoHotkey_L-1.1.33.09.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "qmath.h" see the Fossies "Dox" file reference documentation.

    1 /* ==== ArtNouveaU Quick Math ~ qmath.h ==================================
    2 
    3    WATCOM C/C++ Standard Libraries replacement for tiny code.
    4    Copyright (C) 1997 by the gang at ArtNouveaU, All Rights Reserved.
    5 
    6    Microsoft Visual C/C++ Standard Libraries replacement for tiny code.
    7    Copyright (C) 2002 by Gabriele Scibilia, All Rights Reserved.
    8 
    9         author           : <G>SZ ~ ArtNouveaU
   10         file creation    : 30 March 1997
   11         file description : fast floating point math intrinsics
   12 
   13         revision history :
   14             (30/03/97) the beginning
   15             (24/10/97) renamed WATCOM C/C++ tinymath.h
   16             (26/10/97) added sincos intrinsic
   17             (30/10/97) added acos and asin intrinsics
   18             (31/10/97) added ceil and floor ones
   19             (01/11/97) added hypot, cosh, sinh, acosh, asinh atanh ones
   20             (02/11/97) added tanh intrinsic
   21             (09/01/98) added M_ constants
   22             (27/08/02) renamed MS Visual C/C++ qmath.h
   23             (11/01/04) modified qmathTan() - J.Bennett <jon@hiddensoft.com>
   24 
   25         references       :
   26             ArtNouveaU Tiny Library,
   27             tinymath WATCOM C/C++ intrinsics for math functions,
   28             Gabriele Scibilia, 24 October 1997.
   29 
   30             Pascal/Cubic math intrinsics, 1997.
   31 
   32             WATCOM C/C++ v11.0 Math Library, 1997.
   33 
   34             RTLIB2 small math run time library replacement,
   35             "Art" 64k demo by Farbrausch and Scoopex, 2001.
   36 
   37         notes            : pow returns NaN with non-positive arguments
   38 
   39                            For those who hates "naked" convention
   40                            try modifing each function as the following
   41                            ie.
   42                             i- changing float loads
   43                            ii- removing inlined "ret" statement
   44 
   45                            double _QMATH_LINK qmathSqrt(double __x)
   46                            {
   47                                __asm fld        qword ptr __x
   48                                __asm fsqrt
   49                            }
   50 
   51                            When single precision floating point support
   52                            is required...
   53 
   54                            _QMATH_NAKED _QMATH_INLINE
   55                            float _QMATH_LINK qmathSinFloat(float __x)
   56                            {
   57                                __asm fld       dword ptr [esp + 4]
   58                                __asm fsin
   59                                __asm ret       4
   60                            }
   61 
   62   ======================================================================== */
   63 
   64 #ifndef _QUICKMATH_H_INCLUDED
   65 #define _QUICKMATH_H_INCLUDED
   66 
   67 #ifdef __cplusplus
   68 extern "C" {
   69 #endif
   70 
   71 #if defined(WIN32) && defined(_MSC_VER) && !defined(_WIN64)
   72 #define USE_INLINE_ASM
   73 #endif
   74 
   75 
   76 // Commented out in AutoHotkey v1.0.40.02 to help reduce code size:
   77 //static char quickmath_id[] = "$Id: qmath.h,v 1.1 2004/01/15 19:50:35 jonbennett Exp $";
   78 
   79 // for silly C compilers allowing inlining
   80 // try using "static" definition otherwise
   81 #define _QMATH_INLINE __inline
   82 
   83 // functions are emitted without prolog or epilog code
   84 #define _QMATH_NAKED  __declspec(naked)
   85 
   86 // argument-passing right to left
   87 // called function pops its own arguments from the stack
   88 #define _QMATH_LINK   __stdcall
   89 
   90 #define FIST_MAGIC (((65536.0 * 65536.0 * 16) + 32768.0) * 65536.0)
   91 #define FIST_M0131 (65536.0 * 24.0 * 2.0)
   92 #define FIST_M0230 (65536.0 * 24.0 * 4.0)
   93 #define FIST_M0329 (65536.0 * 24.0 * 8.0)
   94 #define FIST_M0428 (65536.0 * 24.0 * 16.0)
   95 #define FIST_M0527 (65536.0 * 24.0 * 32.0)
   96 #define FIST_M0626 (65536.0 * 24.0 * 64.0)
   97 #define FIST_M0725 (65536.0 * 24.0 * 128.0)
   98 #define FIST_M0824 (65536.0 * 24.0 * 256.0)
   99 #define FIST_M0923 (65536.0 * 24.0 * 512.0)
  100 #define FIST_M1022 (65536.0 * 24.0 * 1024.0)
  101 #define FIST_M1121 (65536.0 * 24.0 * 2048.0)
  102 #define FIST_M1220 (65536.0 * 24.0 * 4096.0)
  103 #define FIST_M1319 (65536.0 * 24.0 * 8192.0)
  104 #define FIST_M1418 (65536.0 * 24.0 * 16384.0)
  105 #define FIST_M1517 (65536.0 * 24.0 * 32768.0)
  106 #define FIST_M1616 (65536.0 * 65536.0 * 24.0 * 1.0)
  107 #define FIST_M1715 (65536.0 * 65536.0 * 24.0 * 2.0)
  108 #define FIST_M1814 (65536.0 * 65536.0 * 24.0 * 4.0)
  109 #define FIST_M1913 (65536.0 * 65536.0 * 24.0 * 8.0)
  110 #define FIST_M2012 (65536.0 * 65536.0 * 24.0 * 16.0)
  111 #define FIST_M2111 (65536.0 * 65536.0 * 24.0 * 32.0)
  112 #define FIST_M2210 (65536.0 * 65536.0 * 24.0 * 64.0)
  113 #define FIST_M2309 (65536.0 * 65536.0 * 24.0 * 128.0)
  114 #define FIST_M2408 (65536.0 * 65536.0 * 24.0 * 256.0)
  115 #define FIST_M2507 (65536.0 * 65536.0 * 24.0 * 512.0)
  116 #define FIST_M2606 (65536.0 * 65536.0 * 24.0 * 1024.0)
  117 #define FIST_M2705 (65536.0 * 65536.0 * 24.0 * 2048.0)
  118 #define FIST_M2804 (65536.0 * 65536.0 * 24.0 * 4096.0)
  119 #define FIST_M2903 (65536.0 * 65536.0 * 24.0 * 8192.0)
  120 #define FIST_M3002 (65536.0 * 65536.0 * 24.0 * 16384.0)
  121 #define FIST_M3101 (65536.0 * 65536.0 * 24.0 * 32768.0)
  122 #define FIST_SHORT (14680064.0f)
  123 
  124 
  125 /*
  126 The following ASM code will convert quickly from a floating point value
  127 to a 16.16 fixed point number.
  128 
  129 This code comes complements of Chris Babcock (a.k.a. "VOR")
  130 
  131 
  132 i_bignum  dq        04238000000000000h
  133 
  134 FADD   [i_bignum]
  135 ...
  136 FSTP  [qword ptr i_temp]
  137 ...
  138 MOV  eax,[dword ptr i_temp]   ; eax = 16.16
  139 */
  140 
  141 
  142 _QMATH_INLINE long qmathFtstNeg(float inval)
  143 {
  144     return ((*(long *) &inval) > 0x80000000);
  145 }
  146 
  147 
  148 _QMATH_INLINE long qmathFtstPos(float inval)
  149 {
  150     return ((*(long *) &inval) < 0x80000000);
  151 }
  152 
  153 
  154 _QMATH_INLINE long qmathFtstZero(float inval)
  155 {
  156     return ((*(long *) &inval) + (*(long *) &inval));
  157 }
  158 
  159 
  160 _QMATH_INLINE long qmathFcompGreatThan(float invala, float invalb)
  161 {
  162     return ((*(long *) &invala) > (*(long *) &invalb));
  163 }
  164 
  165 
  166 _QMATH_INLINE long qmathFcompLessThan(float invala, float invalb)
  167 {
  168     return ((*(long *) &invala) < (*(long *) &invalb));
  169 }
  170 
  171 
  172 _QMATH_INLINE short qmathFistShort(float inval)
  173 {
  174     float dtemp = FIST_SHORT + inval;
  175 
  176     return ((*(short *) &dtemp) & 0x1FFFFF);
  177 }
  178 
  179 
  180 _QMATH_INLINE long qmathFistLong(float inval)
  181 {
  182     double dtemp = FIST_MAGIC + inval;
  183 
  184     return ((*(long *) &dtemp) - 0x80000000);
  185 }
  186 
  187 
  188 _QMATH_INLINE long qmathFist0131(float inval)
  189 {
  190     double dtemp = FIST_M0131 + inval;
  191 
  192     return (*(long *) &dtemp);
  193 }
  194 
  195 
  196 _QMATH_INLINE long qmathFist0230(float inval)
  197 {
  198     double dtemp = FIST_M0230 + inval;
  199 
  200     return (*(long *) &dtemp);
  201 }
  202 
  203 
  204 _QMATH_INLINE long qmathFist0329(float inval)
  205 {
  206     double dtemp = FIST_M0329 + inval;
  207 
  208     return (*(long *) &dtemp);
  209 }
  210 
  211 
  212 _QMATH_INLINE long qmathFist0428(float inval)
  213 {
  214     double dtemp = FIST_M0428 + inval;
  215 
  216     return (*(long *) &dtemp);
  217 }
  218 
  219 
  220 _QMATH_INLINE long qmathFist0527(float inval)
  221 {
  222     double dtemp = FIST_M0527 + inval;
  223 
  224     return (*(long *) &dtemp);
  225 }
  226 
  227 
  228 _QMATH_INLINE long qmathFist0626(float inval)
  229 {
  230     double dtemp = FIST_M0626 + inval;
  231 
  232     return (*(long *) &dtemp);
  233 }
  234 
  235 
  236 _QMATH_INLINE long qmathFist0725(float inval)
  237 {
  238     double dtemp = FIST_M0725 + inval;
  239 
  240     return (*(long *) &dtemp);
  241 }
  242 
  243 
  244 _QMATH_INLINE long qmathFist0824(float inval)
  245 {
  246     double dtemp = FIST_M0824 + inval;
  247 
  248     return (*(long *) &dtemp);
  249 }
  250 
  251 
  252 _QMATH_INLINE long qmathFist0923(float inval)
  253 {
  254     double dtemp = FIST_M0923 + inval;
  255 
  256     return (*(long *) &dtemp);
  257 }
  258 
  259 
  260 _QMATH_INLINE long qmathFist1022(float inval)
  261 {
  262     double dtemp = FIST_M1022 + inval;
  263 
  264     return (*(long *) &dtemp);
  265 }
  266 
  267 
  268 _QMATH_INLINE long qmathFist1121(float inval)
  269 {
  270     double dtemp = FIST_M1121 + inval;
  271 
  272     return (*(long *) &dtemp);
  273 }
  274 
  275 
  276 _QMATH_INLINE long qmathFist1220(float inval)
  277 {
  278     double dtemp = FIST_M1220 + inval;
  279 
  280     return (*(long *) &dtemp);
  281 }
  282 
  283 
  284 _QMATH_INLINE long qmathFist1319(float inval)
  285 {
  286     double dtemp = FIST_M1319 + inval;
  287 
  288     return (*(long *) &dtemp);
  289 }
  290 
  291 
  292 _QMATH_INLINE long qmathFist1418(float inval)
  293 {
  294     double dtemp = FIST_M1418 + inval;
  295 
  296     return (*(long *) &dtemp);
  297 }
  298 
  299 
  300 _QMATH_INLINE long qmathFist1517(float inval)
  301 {
  302     double dtemp = FIST_M1517 + inval;
  303 
  304     return (*(long *) &dtemp);
  305 }
  306 
  307 
  308 _QMATH_INLINE long qmathFist1616(float inval)
  309 {
  310     double dtemp = FIST_M1616 + inval;
  311 
  312     return (*(long *) &dtemp);
  313 }
  314 
  315 
  316 _QMATH_INLINE long qmathFist1715(float inval)
  317 {
  318     double dtemp = FIST_M1715 + inval;
  319 
  320     return (*(long *) &dtemp);
  321 }
  322 
  323 
  324 _QMATH_INLINE long qmathFist1814(float inval)
  325 {
  326     double dtemp = FIST_M1814 + inval;
  327 
  328     return (*(long *) &dtemp);
  329 }
  330 
  331 
  332 _QMATH_INLINE long qmathFist1913(float inval)
  333 {
  334     double dtemp = FIST_M1913 + inval;
  335 
  336     return (*(long *) &dtemp);
  337 }
  338 
  339 
  340 _QMATH_INLINE long qmathFist2012(float inval)
  341 {
  342     double dtemp = FIST_M2012 + inval;
  343 
  344     return (*(long *) &dtemp);
  345 }
  346 
  347 
  348 _QMATH_INLINE long qmathFist2111(float inval)
  349 {
  350     double dtemp = FIST_M2111 + inval;
  351 
  352     return (*(long *) &dtemp);
  353 }
  354 
  355 
  356 _QMATH_INLINE long qmathFist2210(float inval)
  357 {
  358     double dtemp = FIST_M2210 + inval;
  359 
  360     return (*(long *) &dtemp);
  361 }
  362 
  363 
  364 _QMATH_INLINE long qmathFist2309(float inval)
  365 {
  366     double dtemp = FIST_M2309 + inval;
  367 
  368     return (*(long *) &dtemp);
  369 }
  370 
  371 
  372 _QMATH_INLINE long qmathFist2408(float inval)
  373 {
  374     double dtemp = FIST_M2408 + inval;
  375 
  376     return (*(long *) &dtemp);
  377 }
  378 
  379 
  380 _QMATH_INLINE long qmathFist2507(float inval)
  381 {
  382     double dtemp = FIST_M2507 + inval;
  383 
  384     return (*(long *) &dtemp);
  385 }
  386 
  387 
  388 _QMATH_INLINE long qmathFist2606(float inval)
  389 {
  390     double dtemp = FIST_M2606 + inval;
  391 
  392     return (*(long *) &dtemp);
  393 }
  394 
  395 
  396 _QMATH_INLINE long qmathFist2705(float inval)
  397 {
  398     double dtemp = FIST_M2705 + inval;
  399 
  400     return (*(long *) &dtemp);
  401 }
  402 
  403 
  404 _QMATH_INLINE long qmathFist2804(float inval)
  405 {
  406     double dtemp = FIST_M2804 + inval;
  407 
  408     return (*(long *) &dtemp);
  409 }
  410 
  411 
  412 _QMATH_INLINE long qmathFist2903(float inval)
  413 {
  414     double dtemp = FIST_M2903 + inval;
  415 
  416     return (*(long *) &dtemp);
  417 }
  418 
  419 
  420 _QMATH_INLINE long qmathFist3002(float inval)
  421 {
  422     double dtemp = FIST_M3002 + inval;
  423 
  424     return (*(long *) &dtemp);
  425 }
  426 
  427 
  428 _QMATH_INLINE long qmathFist3101(float inval)
  429 {
  430     double dtemp = FIST_M3101 + inval;
  431 
  432     return (*(long *) &dtemp);
  433 }
  434 
  435 
  436 // M_ constants
  437 #define M_E        (2.71828182845904523536)
  438 #define M_LOG2E    (1.44269504088896340736)
  439 #define M_LOG10E   (0.434294481903251827651)
  440 #define M_LN2      (0.693147180559945309417)
  441 #define M_LN10     (2.30258509299404568402)
  442 #define M_PI       (3.14159265358979323846)
  443 #define M_PI_2     (1.57079632679489661923)
  444 #define M_PI_4     (0.785398163397448309616)
  445 #define M_1_PI     (0.318309886183790671538)
  446 #define M_2_PI     (0.636619772367581343076)
  447 #define M_1_SQRTPI (0.564189583547756286948)
  448 #define M_2_SQRTPI (1.12837916709551257390)
  449 #define M_SQRT2    (1.41421356237309504880)
  450 #define M_SQRT_2   (0.707106781186547524401)
  451 
  452 
  453 #ifdef USE_INLINE_ASM
  454 
  455 
  456 _QMATH_NAKED _QMATH_INLINE
  457 double _QMATH_LINK qmathSin(double __x)
  458 {
  459     __asm fld       qword ptr [esp + 4]
  460     __asm fsin
  461     __asm ret       8
  462 }
  463 
  464 
  465 static double einhalb = 0.5;
  466 
  467 _QMATH_NAKED _QMATH_INLINE
  468 double _QMATH_LINK qmathAsin(double __x)
  469 {
  470     __asm fld       qword ptr [esp + 4]
  471     __asm fld       st
  472     __asm fabs
  473     __asm fcom      dword ptr [einhalb]
  474     __asm fstsw     ax
  475     __asm sahf
  476     __asm jbe       asin_kleiner
  477     __asm fld1
  478     __asm fsubrp    st(1), st(0)
  479     __asm fld       st
  480     __asm fadd      st(0), st(0)
  481     __asm fxch      st(1)
  482     __asm fmul      st(0), st(0)
  483     __asm fsubp     st(1), st(0)
  484     __asm jmp       asin_exit
  485 
  486 asin_kleiner:
  487 
  488     __asm fstp      st(0)
  489     __asm fld       st(0)
  490     __asm fmul      st(0), st(0)
  491     __asm fld1
  492     __asm fsubrp    st(1), st(0)
  493 
  494 asin_exit:
  495 
  496     __asm fsqrt
  497     __asm fpatan
  498     __asm ret       8
  499 }
  500 
  501 
  502 _QMATH_NAKED _QMATH_INLINE
  503 double _QMATH_LINK qmathCos(double __x)
  504 {
  505     __asm fld       qword ptr [esp + 4]
  506     __asm fcos
  507     __asm ret       8
  508 }
  509 
  510 
  511 _QMATH_NAKED _QMATH_INLINE
  512 double _QMATH_LINK qmathAcos(double __x)
  513 {
  514     __asm fld       qword ptr [esp + 4]
  515     __asm fld1
  516     __asm fchs
  517     __asm fcomp     st(1)
  518     __asm fstsw     ax
  519     __asm je        acos_suckt
  520 
  521     __asm fld       st(0)
  522     __asm fld1
  523     __asm fsubrp    st(1), st(0)
  524     __asm fxch      st(1)
  525     __asm fld1
  526     __asm faddp     st(1), st(0)
  527     __asm fdivp     st(1), st(0)
  528     __asm fsqrt
  529     __asm fld1
  530     __asm jmp       acos_exit
  531 
  532 acos_suckt:
  533 
  534     __asm fld1
  535     __asm fldz
  536 
  537 acos_exit:
  538 
  539     __asm fpatan
  540     __asm fadd      st(0), st(0)
  541     __asm ret       8
  542 }
  543 
  544 
  545 /* J.Bennett - added fstp in tan function to remove 1.0 it pushes onto the stack */
  546 
  547 _QMATH_NAKED _QMATH_INLINE
  548 double _QMATH_LINK qmathTan(double __x)
  549 {
  550     __asm fld       qword ptr [esp + 4]
  551     __asm fptan
  552     __asm fstp      st(0)
  553     __asm ret       8
  554 }
  555 
  556 
  557 _QMATH_NAKED _QMATH_INLINE
  558 double _QMATH_LINK qmathAtan(double __x)
  559 {
  560     __asm fld       qword ptr [esp + 4]
  561     __asm fld1
  562     __asm fpatan
  563     __asm ret       8
  564 }
  565 
  566 
  567 _QMATH_NAKED _QMATH_INLINE
  568 double _QMATH_LINK qmathAtan2(double __y, double __x)
  569 {
  570     __asm fld       qword ptr [esp +  4]
  571     __asm fld       qword ptr [esp + 12]
  572     __asm fpatan
  573     __asm ret       16
  574 }
  575 
  576 
  577 _QMATH_NAKED _QMATH_INLINE
  578 double _QMATH_LINK qmathExp(double __x)
  579 {
  580     __asm fld       qword ptr [esp + 4];
  581     __asm fldl2e
  582     __asm fmulp     st(1), st
  583     __asm fld1
  584     __asm fld       st(1)
  585     __asm fprem
  586     __asm f2xm1
  587     __asm faddp     st(1), st
  588     __asm fscale
  589     __asm fxch
  590     __asm fstp      st
  591     __asm ret       8
  592 }
  593 
  594 
  595 _QMATH_NAKED _QMATH_INLINE
  596 double _QMATH_LINK qmathExp2(double __x)
  597 {
  598     __asm fld       qword ptr [esp + 4];
  599     __asm fld1
  600     __asm fld       st(1)
  601     __asm fprem
  602     __asm f2xm1
  603     __asm faddp     st(1), st
  604     __asm fscale
  605     __asm fxch
  606     __asm fstp      st
  607     __asm ret       8
  608 }
  609 
  610 
  611 _QMATH_NAKED _QMATH_INLINE
  612 double _QMATH_LINK qmathExp10(double __x)
  613 {
  614     __asm fld       qword ptr [esp + 4];
  615     __asm fldl2t
  616     __asm fmulp     st(1), st
  617     __asm fld1
  618     __asm fld       st(1)
  619     __asm fprem
  620     __asm f2xm1
  621     __asm faddp     st(1), st
  622     __asm fscale
  623     __asm fxch
  624     __asm fstp      st
  625     __asm ret       8
  626 }
  627 
  628 
  629 _QMATH_NAKED _QMATH_INLINE
  630 double _QMATH_LINK qmathLog(double __x)
  631 {
  632     __asm fld       qword ptr [esp + 4]
  633     __asm fldln2
  634     __asm fxch
  635     __asm fyl2x
  636     __asm ret       8
  637 }
  638 
  639 
  640 _QMATH_NAKED _QMATH_INLINE
  641 double _QMATH_LINK qmathLog2(double __x)
  642 {
  643     __asm fld       qword ptr [esp + 4]
  644     __asm fld1
  645     __asm fxch
  646     __asm fyl2x
  647     __asm ret       8
  648 }
  649 
  650 
  651 _QMATH_NAKED _QMATH_INLINE
  652 double _QMATH_LINK qmathLog10(double __x)
  653 {
  654     __asm fld       qword ptr [esp + 4]
  655     __asm fldlg2
  656     __asm fxch
  657     __asm fyl2x
  658     __asm ret       8
  659 }
  660 
  661 
  662 _QMATH_NAKED _QMATH_INLINE
  663 double _QMATH_LINK qmathFabs(double __x)
  664 {
  665     __asm fld       qword ptr [esp + 4]
  666     __asm fabs
  667     __asm ret       8
  668 }
  669 
  670 
  671 _QMATH_NAKED _QMATH_INLINE
  672 double _QMATH_LINK qmathPow(double __x, double __y)
  673 {
  674     __asm fld       qword ptr [esp + 12]
  675     __asm fld       qword ptr [esp +  4]
  676     __asm ftst
  677     __asm fstsw     ax
  678     __asm sahf
  679     __asm jz        pow_zero
  680 
  681     __asm fyl2x
  682     __asm fld1
  683     __asm fld       st(1)
  684     __asm fprem
  685     __asm f2xm1
  686     __asm faddp     st(1), st(0)
  687     __asm fscale
  688 
  689 pow_zero:
  690 
  691     __asm fstp      st(1)
  692     __asm ret       16
  693 }
  694 
  695 
  696 _QMATH_NAKED _QMATH_INLINE
  697 double _QMATH_LINK qmathCeil(double __x)
  698 {
  699     __asm fld       qword ptr [esp + 4]
  700     __asm fchs
  701     __asm fld1
  702     __asm fld       st(1)
  703     __asm fprem
  704     __asm sub       esp, 4
  705     __asm fst       dword ptr [esp]
  706     __asm fxch      st(2)
  707     __asm mov       eax, [esp]
  708     __asm cmp       eax, 0x80000000
  709     __asm jbe       ceil_exit
  710     __asm fsub      st, st(1)
  711 
  712 ceil_exit:
  713 
  714     __asm fsub      st, st(2)
  715     __asm fstp      st(1)
  716     __asm fstp      st(1)
  717     __asm fchs
  718     __asm pop       eax
  719     __asm ret       8
  720 }
  721 
  722 
  723 _QMATH_NAKED _QMATH_INLINE
  724 double _QMATH_LINK qmathFloor(double __x)
  725 {
  726     __asm fld       qword ptr [esp + 4]
  727     __asm fld1
  728     __asm fld       st(1)
  729     __asm fprem
  730     __asm sub       esp, 4
  731     __asm fst       dword ptr [esp]
  732     __asm fxch      st(2)
  733     __asm mov       eax, [esp]
  734     __asm cmp       eax, 0x80000000
  735     __asm jbe       floor_exit
  736     __asm fsub      st, st(1)
  737 
  738 floor_exit:
  739 
  740     __asm fsub      st, st(2)
  741     __asm fstp      st(1)
  742     __asm fstp      st(1)
  743     __asm pop       eax
  744     __asm ret       8
  745 }
  746 
  747 
  748 _QMATH_NAKED _QMATH_INLINE
  749 double _QMATH_LINK qmathFmod(double __x, double __y)
  750 {
  751     __asm fld       qword ptr [esp + 12]
  752     __asm fld       qword ptr [esp +  4]
  753     __asm fprem
  754     __asm fxch
  755     __asm fstp      st
  756     __asm ret       16
  757 }
  758 
  759 
  760 _QMATH_NAKED _QMATH_INLINE
  761 double _QMATH_LINK qmathSqrt(double __x)
  762 {
  763     __asm fld       qword ptr [esp + 4]
  764     __asm fsqrt
  765     __asm ret       8
  766 }
  767 
  768 
  769 _QMATH_NAKED _QMATH_INLINE
  770 double _QMATH_LINK qmathHypot(double __x, double __y)
  771 {
  772     __asm fld       qword ptr [esp + 12]
  773     __asm fld       qword ptr [esp +  4]
  774     __asm fmul      st, st
  775     __asm fxch
  776     __asm fmul      st, st
  777     __asm faddp     st(1), st
  778     __asm fsqrt
  779     __asm ret       16
  780 }
  781 
  782 
  783 _QMATH_NAKED _QMATH_INLINE
  784 double _QMATH_LINK qmathAcosh(double __x)
  785 {
  786     __asm fld       qword ptr [esp + 4]
  787     __asm fld       st
  788     __asm fmul      st, st
  789     __asm fld1
  790     __asm fsubp     st(1), st
  791     __asm fsqrt
  792     __asm faddp     st(1), st
  793     __asm fldln2
  794     __asm fxch
  795     __asm fyl2x
  796     __asm ret       8
  797 }
  798 
  799 
  800 _QMATH_NAKED _QMATH_INLINE
  801 double _QMATH_LINK qmathAsinh(double __x)
  802 {
  803     __asm fld       qword ptr [esp + 4]
  804     __asm fld       st
  805     __asm fmul      st, st
  806     __asm fld1
  807     __asm faddp     st(1), st
  808     __asm fsqrt
  809     __asm faddp     st(1), st
  810     __asm fldln2
  811     __asm fxch
  812     __asm fyl2x
  813     __asm ret       8
  814 }
  815 
  816 
  817 _QMATH_NAKED _QMATH_INLINE
  818 double _QMATH_LINK qmathAtanh(double __x)
  819 {
  820     __asm fld       qword ptr [esp + 4]
  821     __asm fld1
  822     __asm fsub      st, st(1)
  823     __asm fld1
  824     __asm faddp     st(2), st
  825     __asm fdivrp    st(1), st
  826     __asm fldln2
  827     __asm fxch
  828     __asm fyl2x
  829     __asm mov       eax, 0xBF000000
  830     __asm push      eax
  831     __asm fld       dword ptr [esp]
  832     __asm fmulp     st(1), st
  833     __asm pop       eax
  834     __asm ret       8
  835 }
  836 
  837 
  838 _QMATH_NAKED _QMATH_INLINE
  839 double _QMATH_LINK qmathCosh(double __x)
  840 {
  841     __asm fld       qword ptr [esp + 4]
  842     __asm fldl2e
  843     __asm fmulp     st(1), st
  844     __asm fld1
  845     __asm fld       st(1)
  846     __asm fprem
  847     __asm f2xm1
  848     __asm faddp     st(1), st
  849     __asm fscale
  850     __asm fxch
  851     __asm fstp      st
  852     __asm fld1
  853     __asm fdiv      st, st(1)
  854     __asm faddp     st(1), st
  855     __asm mov       eax, 0x3F000000
  856     __asm push      eax
  857     __asm fld       dword ptr [esp]
  858     __asm fmulp     st(1), st
  859     __asm pop       eax
  860     __asm ret       8
  861 }
  862 
  863 
  864 _QMATH_NAKED _QMATH_INLINE
  865 double _QMATH_LINK qmathSinh(double __x)
  866 {
  867     __asm fld       qword ptr [esp + 4]
  868     __asm fldl2e
  869     __asm fmulp     st(1), st
  870     __asm fld1
  871     __asm fld       st(1)
  872     __asm fprem
  873     __asm f2xm1
  874     __asm faddp     st(1), st
  875     __asm fscale
  876     __asm fxch
  877     __asm fstp      st
  878     __asm fld1
  879     __asm fdiv      st, st(1)
  880     __asm fsubp     st(1), st
  881     __asm mov       eax, 0x3F000000
  882     __asm push      eax
  883     __asm fld       dword ptr [esp]
  884     __asm fmulp     st(1), st
  885     __asm pop       eax
  886     __asm ret       8
  887 }
  888 
  889 
  890 _QMATH_NAKED _QMATH_INLINE
  891 double _QMATH_LINK qmathTanh(double __x)
  892 {
  893     __asm fld       qword ptr [esp + 4]
  894     __asm fld       st
  895     __asm mov       eax, 0x40000000
  896     __asm push      eax
  897     __asm fld       dword ptr [esp]
  898     __asm fmul      st, st(1)
  899     __asm fldl2e
  900     __asm fmulp     st(1), st
  901     __asm fld1
  902     __asm fld       st(1)
  903     __asm fprem
  904     __asm f2xm1
  905     __asm faddp     st(1), st
  906     __asm fscale
  907     __asm fxch
  908     __asm fstp      st
  909     __asm fld1
  910     __asm fsub      st, st(1)
  911     __asm fchs
  912     __asm fld1
  913     __asm faddp     st(2), st
  914     __asm fdivrp    st(1), st
  915     __asm pop       eax
  916     __asm ret       8
  917 }
  918 
  919 
  920 #else // USE_INLINE_ASM not defined
  921 
  922 #include <math.h>
  923 
  924 // Inline assembly isn't available, so qmath is essentially disabled.
  925 // Define a bunch of macros instead, for convenience:
  926 #define qmathSin    sin
  927 #define qmathAsin   asin
  928 #define qmathCos    cos
  929 #define qmathAcos   acos
  930 #define qmathTan    tan
  931 #define qmathAtan   atan
  932 #define qmathAtan2  atan2
  933 #define qmathExp    exp
  934 #define qmathExp2   exp2
  935 #define qmathExp10(a) pow(10, a)
  936 #define qmathLog    log
  937 #define qmathLog2   log
  938 #define qmathLog10(a) log10(double(a))
  939 #define qmathFabs   fabs
  940 #define qmathPow(a,b) pow(double(a),double(b))
  941 #define qmathCeil   ceil
  942 #define qmathFloor  floor
  943 #define qmathFmod   fmod
  944 #define qmathSqrt   sqrt
  945 #define qmathHypot(a,b) sqrt(pow(double(a), 2.0) + pow(double(b), 2.0));
  946 #define qmathAcosh  acosh
  947 #define qmathAsinh  asinh
  948 #define qmathAtanh  atanh
  949 #define qmathCosh   cosh
  950 #define qmathSinh   sinh
  951 #define qmathTanh   tanh
  952 
  953 #endif
  954 
  955 
  956 #ifdef __cplusplus
  957   };
  958 #endif
  959 
  960 #endif // _QUICKMATH_H_INCLUDED