… | |
… | |
554 | || defined _M_IX86 || defined _M_AMD64 || defined _M_IA64 |
554 | || defined _M_IX86 || defined _M_AMD64 || defined _M_IA64 |
555 | #define ECB_STDFP 1 |
555 | #define ECB_STDFP 1 |
556 | #include <string.h> /* for memcpy */ |
556 | #include <string.h> /* for memcpy */ |
557 | #else |
557 | #else |
558 | #define ECB_STDFP 0 |
558 | #define ECB_STDFP 0 |
|
|
559 | #include <math.h> /* for frexp*, ldexp* */ |
559 | #endif |
560 | #endif |
560 | |
561 | |
561 | #ifndef ECB_NO_LIBM |
562 | #ifndef ECB_NO_LIBM |
562 | |
563 | |
563 | /* convert a float to ieee single/binary32 */ |
564 | /* convert a float to ieee single/binary32 */ |
… | |
… | |
569 | |
570 | |
570 | #if ECB_STDFP |
571 | #if ECB_STDFP |
571 | memcpy (&r, &x, 4); |
572 | memcpy (&r, &x, 4); |
572 | #else |
573 | #else |
573 | /* slow emulation, works for anything but -0 */ |
574 | /* slow emulation, works for anything but -0 */ |
574 | ECB_EXTERN_C float frexpf (float v, int *e); |
|
|
575 | uint32_t m; |
575 | uint32_t m; |
576 | int e; |
576 | int e; |
577 | |
577 | |
578 | if (x == 0e0f ) return 0x00000000U; |
578 | if (x == 0e0f ) return 0x00000000U; |
579 | if (x > +3.40282346638528860e+38f) return 0x7f800000U; |
579 | if (x > +3.40282346638528860e+38f) return 0x7f800000U; |
… | |
… | |
610 | |
610 | |
611 | #if ECB_STDFP |
611 | #if ECB_STDFP |
612 | memcpy (&r, &x, 4); |
612 | memcpy (&r, &x, 4); |
613 | #else |
613 | #else |
614 | /* emulation, only works for normals and subnormals and +0 */ |
614 | /* emulation, only works for normals and subnormals and +0 */ |
615 | ECB_EXTERN_C float ldexpf (float x, int e); |
|
|
616 | |
|
|
617 | int neg = x >> 31; |
615 | int neg = x >> 31; |
618 | int e = (x >> 23) & 0xffU; |
616 | int e = (x >> 23) & 0xffU; |
619 | |
617 | |
620 | x &= 0x7fffffU; |
618 | x &= 0x7fffffU; |
621 | |
619 | |
… | |
… | |
642 | |
640 | |
643 | #if ECB_STDFP |
641 | #if ECB_STDFP |
644 | memcpy (&r, &x, 8); |
642 | memcpy (&r, &x, 8); |
645 | #else |
643 | #else |
646 | /* slow emulation, works for anything but -0 */ |
644 | /* slow emulation, works for anything but -0 */ |
647 | ECB_EXTERN_C double frexp (double v, int *e); |
|
|
648 | uint64_t m; |
645 | uint64_t m; |
649 | int e; |
646 | int e; |
650 | |
647 | |
651 | if (x == 0e0 ) return 0x0000000000000000U; |
648 | if (x == 0e0 ) return 0x0000000000000000U; |
652 | if (x > +1.79769313486231470e+308) return 0x7ff0000000000000U; |
649 | if (x > +1.79769313486231470e+308) return 0x7ff0000000000000U; |
… | |
… | |
683 | |
680 | |
684 | #if ECB_STDFP |
681 | #if ECB_STDFP |
685 | memcpy (&r, &x, 8); |
682 | memcpy (&r, &x, 8); |
686 | #else |
683 | #else |
687 | /* emulation, only works for normals and subnormals and +0 */ |
684 | /* emulation, only works for normals and subnormals and +0 */ |
688 | ECB_EXTERN_C double ldexp (double x, int e); |
|
|
689 | |
|
|
690 | int neg = x >> 63; |
685 | int neg = x >> 63; |
691 | int e = (x >> 52) & 0x7ffU; |
686 | int e = (x >> 52) & 0x7ffU; |
692 | |
687 | |
693 | x &= 0xfffffffffffffU; |
688 | x &= 0xfffffffffffffU; |
694 | |
689 | |