… | |
… | |
558 | #define ECB_STDFP 0 |
558 | #define ECB_STDFP 0 |
559 | #endif |
559 | #endif |
560 | |
560 | |
561 | #ifndef ECB_NO_LIBM |
561 | #ifndef ECB_NO_LIBM |
562 | |
562 | |
563 | #if __STDC_IEC_559__ || ECB_STDFP |
|
|
564 | /* we assume this is defined for most C and many C++ compilers */ |
|
|
565 | ecb_inline ecb_bool ecb_float_ieee (void) ecb_const; |
|
|
566 | ecb_inline ecb_bool ecb_float_ieee (void) { return 1; } |
|
|
567 | ecb_inline ecb_bool ecb_double_ieee (void) ecb_const; |
|
|
568 | ecb_inline ecb_bool ecb_double_ieee (void) { return 1; } |
|
|
569 | #elif ECB_CPP |
|
|
570 | #include <limits> |
|
|
571 | ecb_inline ecb_bool ecb_float_ieee (void) ecb_const; |
|
|
572 | ecb_inline ecb_bool ecb_float_ieee (void) { return std::numeric_limits<float >::is_iec559; } |
|
|
573 | ecb_inline ecb_bool ecb_double_ieee (void) ecb_const; |
|
|
574 | ecb_inline ecb_bool ecb_double_ieee (void) { return std::numeric_limits<double>::is_iec559; } |
|
|
575 | #else |
|
|
576 | ecb_inline ecb_bool ecb_float_ieee (void) ecb_const; |
|
|
577 | ecb_inline ecb_bool ecb_float_ieee (void) { return 0; } |
|
|
578 | ecb_inline ecb_bool ecb_double_ieee (void) ecb_const; |
|
|
579 | ecb_inline ecb_bool ecb_double_ieee (void) { return 0; } |
|
|
580 | #endif |
|
|
581 | |
|
|
582 | /* convert a float to ieee single/binary32 */ |
563 | /* convert a float to ieee single/binary32 */ |
583 | ecb_function_ uint32_t ecb_float_to_binary32 (float x) ecb_const; |
564 | ecb_function_ uint32_t ecb_float_to_binary32 (float x) ecb_const; |
584 | ecb_function_ uint32_t |
565 | ecb_function_ uint32_t |
585 | ecb_float_to_binary32 (float x) |
566 | ecb_float_to_binary32 (float x) |
586 | { |
567 | { |
… | |
… | |
670 | if (x == 0e0 ) return 0; |
651 | if (x == 0e0 ) return 0; |
671 | if (x > +1.79769313486231470e+308) return 0x7ff0000000000000U; |
652 | if (x > +1.79769313486231470e+308) return 0x7ff0000000000000U; |
672 | if (x < -1.79769313486231470e+308) return 0xfff0000000000000U; |
653 | if (x < -1.79769313486231470e+308) return 0xfff0000000000000U; |
673 | if (x != x ) return 0X7ff7ffffffffffffU; |
654 | if (x != x ) return 0X7ff7ffffffffffffU; |
674 | |
655 | |
675 | m = frexpf (x, &e) * 0x1000000U; |
|
|
676 | m = frexp (x, &e) * 0x20000000000000U; |
656 | m = frexp (x, &e) * 0x20000000000000U; |
677 | |
657 | |
678 | r = m & 0x8000000000000000;; |
658 | r = m & 0x8000000000000000;; |
679 | |
659 | |
680 | if (r) |
660 | if (r) |
… | |
… | |
715 | if (e) |
695 | if (e) |
716 | x |= 0x10000000000000U; |
696 | x |= 0x10000000000000U; |
717 | else |
697 | else |
718 | e = 1; |
698 | e = 1; |
719 | |
699 | |
720 | /* we distrust ldexpf a bit and do the 2**-53 scaling by an extra multiply */ |
700 | /* we distrust ldexp a bit and do the 2**-53 scaling by an extra multiply */ |
721 | r = ldexp (x * (1. / 0x20000000000000U), e - 1022); |
701 | r = ldexp (x * (1. / 0x20000000000000U), e - 1022); |
722 | |
702 | |
723 | r = neg ? -r : r; |
703 | r = neg ? -r : r; |
724 | #endif |
704 | #endif |
725 | |
705 | |