git repos / blockattack-game

blame: source/code/Libs/include/cereal/external/rapidjson/internal/ieee754.h

normal view · raw

6c5f2c01 sago007 2017-03-15 17:56 1
// Tencent is pleased to support the open source community by making RapidJSON available.
6c5f2c01 sago007 2017-03-15 17:56 2
// 
6c5f2c01 sago007 2017-03-15 17:56 3
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
6c5f2c01 sago007 2017-03-15 17:56 4
//
6c5f2c01 sago007 2017-03-15 17:56 5
// Licensed under the MIT License (the "License"); you may not use this file except
6c5f2c01 sago007 2017-03-15 17:56 6
// in compliance with the License. You may obtain a copy of the License at
6c5f2c01 sago007 2017-03-15 17:56 7
//
6c5f2c01 sago007 2017-03-15 17:56 8
// http://opensource.org/licenses/MIT
6c5f2c01 sago007 2017-03-15 17:56 9
//
6c5f2c01 sago007 2017-03-15 17:56 10
// Unless required by applicable law or agreed to in writing, software distributed 
6c5f2c01 sago007 2017-03-15 17:56 11
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
6c5f2c01 sago007 2017-03-15 17:56 12
// CONDITIONS OF ANY KIND, either express or implied. See the License for the 
6c5f2c01 sago007 2017-03-15 17:56 13
// specific language governing permissions and limitations under the License.
6c5f2c01 sago007 2017-03-15 17:56 14
6c5f2c01 sago007 2017-03-15 17:56 15
#ifndef CEREAL_RAPIDJSON_IEEE754_
6c5f2c01 sago007 2017-03-15 17:56 16
#define CEREAL_RAPIDJSON_IEEE754_
6c5f2c01 sago007 2017-03-15 17:56 17
6c5f2c01 sago007 2017-03-15 17:56 18
#include "../rapidjson.h"
6c5f2c01 sago007 2017-03-15 17:56 19
6c5f2c01 sago007 2017-03-15 17:56 20
CEREAL_RAPIDJSON_NAMESPACE_BEGIN
6c5f2c01 sago007 2017-03-15 17:56 21
namespace internal {
6c5f2c01 sago007 2017-03-15 17:56 22
6c5f2c01 sago007 2017-03-15 17:56 23
class Double {
6c5f2c01 sago007 2017-03-15 17:56 24
public:
6c5f2c01 sago007 2017-03-15 17:56 25
    Double() {}
6c5f2c01 sago007 2017-03-15 17:56 26
    Double(double d) : d_(d) {}
6c5f2c01 sago007 2017-03-15 17:56 27
    Double(uint64_t u) : u_(u) {}
6c5f2c01 sago007 2017-03-15 17:56 28
6c5f2c01 sago007 2017-03-15 17:56 29
    double Value() const { return d_; }
6c5f2c01 sago007 2017-03-15 17:56 30
    uint64_t Uint64Value() const { return u_; }
6c5f2c01 sago007 2017-03-15 17:56 31
6c5f2c01 sago007 2017-03-15 17:56 32
    double NextPositiveDouble() const {
6c5f2c01 sago007 2017-03-15 17:56 33
        CEREAL_RAPIDJSON_ASSERT(!Sign());
6c5f2c01 sago007 2017-03-15 17:56 34
        return Double(u_ + 1).Value();
6c5f2c01 sago007 2017-03-15 17:56 35
    }
6c5f2c01 sago007 2017-03-15 17:56 36
6c5f2c01 sago007 2017-03-15 17:56 37
    bool Sign() const { return (u_ & kSignMask) != 0; }
6c5f2c01 sago007 2017-03-15 17:56 38
    uint64_t Significand() const { return u_ & kSignificandMask; }
6c5f2c01 sago007 2017-03-15 17:56 39
    int Exponent() const { return static_cast<int>(((u_ & kExponentMask) >> kSignificandSize) - kExponentBias); }
6c5f2c01 sago007 2017-03-15 17:56 40
6c5f2c01 sago007 2017-03-15 17:56 41
    bool IsNan() const { return (u_ & kExponentMask) == kExponentMask && Significand() != 0; }
6c5f2c01 sago007 2017-03-15 17:56 42
    bool IsInf() const { return (u_ & kExponentMask) == kExponentMask && Significand() == 0; }
6c5f2c01 sago007 2017-03-15 17:56 43
    bool IsNanOrInf() const { return (u_ & kExponentMask) == kExponentMask; }
6c5f2c01 sago007 2017-03-15 17:56 44
    bool IsNormal() const { return (u_ & kExponentMask) != 0 || Significand() == 0; }
6c5f2c01 sago007 2017-03-15 17:56 45
    bool IsZero() const { return (u_ & (kExponentMask | kSignificandMask)) == 0; }
6c5f2c01 sago007 2017-03-15 17:56 46
6c5f2c01 sago007 2017-03-15 17:56 47
    uint64_t IntegerSignificand() const { return IsNormal() ? Significand() | kHiddenBit : Significand(); }
6c5f2c01 sago007 2017-03-15 17:56 48
    int IntegerExponent() const { return (IsNormal() ? Exponent() : kDenormalExponent) - kSignificandSize; }
6c5f2c01 sago007 2017-03-15 17:56 49
    uint64_t ToBias() const { return (u_ & kSignMask) ? ~u_ + 1 : u_ | kSignMask; }
6c5f2c01 sago007 2017-03-15 17:56 50
6c5f2c01 sago007 2017-03-15 17:56 51
    static unsigned EffectiveSignificandSize(int order) {
6c5f2c01 sago007 2017-03-15 17:56 52
        if (order >= -1021)
6c5f2c01 sago007 2017-03-15 17:56 53
            return 53;
6c5f2c01 sago007 2017-03-15 17:56 54
        else if (order <= -1074)
6c5f2c01 sago007 2017-03-15 17:56 55
            return 0;
6c5f2c01 sago007 2017-03-15 17:56 56
        else
6c5f2c01 sago007 2017-03-15 17:56 57
            return static_cast<unsigned>(order) + 1074;
6c5f2c01 sago007 2017-03-15 17:56 58
    }
6c5f2c01 sago007 2017-03-15 17:56 59
6c5f2c01 sago007 2017-03-15 17:56 60
private:
6c5f2c01 sago007 2017-03-15 17:56 61
    static const int kSignificandSize = 52;
6c5f2c01 sago007 2017-03-15 17:56 62
    static const int kExponentBias = 0x3FF;
6c5f2c01 sago007 2017-03-15 17:56 63
    static const int kDenormalExponent = 1 - kExponentBias;
6c5f2c01 sago007 2017-03-15 17:56 64
    static const uint64_t kSignMask = CEREAL_RAPIDJSON_UINT64_C2(0x80000000, 0x00000000);
6c5f2c01 sago007 2017-03-15 17:56 65
    static const uint64_t kExponentMask = CEREAL_RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000);
6c5f2c01 sago007 2017-03-15 17:56 66
    static const uint64_t kSignificandMask = CEREAL_RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF);
6c5f2c01 sago007 2017-03-15 17:56 67
    static const uint64_t kHiddenBit = CEREAL_RAPIDJSON_UINT64_C2(0x00100000, 0x00000000);
6c5f2c01 sago007 2017-03-15 17:56 68
6c5f2c01 sago007 2017-03-15 17:56 69
    union {
6c5f2c01 sago007 2017-03-15 17:56 70
        double d_;
6c5f2c01 sago007 2017-03-15 17:56 71
        uint64_t u_;
6c5f2c01 sago007 2017-03-15 17:56 72
    };
6c5f2c01 sago007 2017-03-15 17:56 73
};
6c5f2c01 sago007 2017-03-15 17:56 74
6c5f2c01 sago007 2017-03-15 17:56 75
} // namespace internal
6c5f2c01 sago007 2017-03-15 17:56 76
CEREAL_RAPIDJSON_NAMESPACE_END
6c5f2c01 sago007 2017-03-15 17:56 77
6c5f2c01 sago007 2017-03-15 17:56 78
#endif // CEREAL_RAPIDJSON_IEEE754_
1970-01-01 00:00 79