Skip to content

fix: centos下数据计算不一致 #8

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions deterministic/glacier_float.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
#include <stdint.h>
#include <cmath>

//#define GLACIER_MULTIPLY_NORAMLIZE_FAST

/**
* Uncomment the below when you want use GFloat in an union.
* Take in mind that the default value will not guaranteed to be Zero anymore!
*/
// #define GLACIER_UNION_COMPATIBLE //Fixes compilation error in an union

// #define GLACIER_MULTIPLY_NORAMLIZE_FAST


#ifndef GLACIER_MULTIPLY_NORAMLIZE_FAST
//#define GLACIER_NORMALIZE_TEST
Expand Down Expand Up @@ -110,12 +118,16 @@ class GFloat // Get Glacier first char "G" for Name

static void Init();

#ifdef GLACIER_UNION_COMPATIBLE
inline GFloat()=default;
#else
constexpr GFloat(const GFloat&) = default;

constexpr GFloat() : rawint32(0)
{

}
#endif

explicit inline GFloat( int32_t TValue)
{
Expand Down Expand Up @@ -149,7 +161,7 @@ class GFloat // Get Glacier first char "G" for Name
{
int64_t TValue = (int64_t)b * (int64_t)Traw32 + (int64_t)a;

int32_t index = GBitScanReverse64( (uint64_t)abs(TValue));
int32_t index = GBitScanReverse64( (uint64_t)std::abs(TValue));

int32_t exp = 62 - index;

Expand Down Expand Up @@ -184,9 +196,7 @@ class GFloat // Get Glacier first char "G" for Name

static inline constexpr GFloat FromRaw32(int32_t Traw32)
{
GFloat T;
T.rawint32 = Traw32;
return T;
return GFloat(Traw32>>8,Traw32);
}

static inline constexpr GFloat FromFractionAndExp(int32_t Traw32, int32_t exp)
Expand Down Expand Up @@ -235,7 +245,7 @@ class GFloat // Get Glacier first char "G" for Name
if (Trawvalue == 0)
return GFloat(0, 0);

int32_t index = GBitScanReverse32(abs(Trawvalue));
int32_t index = GBitScanReverse32(std::abs(Trawvalue));

if (index <= 22)
{
Expand All @@ -254,7 +264,7 @@ class GFloat // Get Glacier first char "G" for Name
if( Trawvalue == 0 )
return GFloat(0,0);

int32_t index = GBitScanReverse64(abs(Trawvalue ));
int32_t index = GBitScanReverse64(std::abs(Trawvalue ));

if ( index <= 22 )
{
Expand All @@ -270,7 +280,7 @@ class GFloat // Get Glacier first char "G" for Name

inline bool IsNormalize() const
{
int32_t absRaw = abs( getfraction());
int32_t absRaw = std::abs(getfraction());

if ( absRaw !=0 && ( absRaw < 0x00400000 || absRaw > 0x007FFFFF))
{
Expand Down