Skip to content

Commit 36ecbe3

Browse files
committed
Fixed emulated_float64_t bug
1 parent 279774c commit 36ecbe3

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

include/nbl/builtin/hlsl/emulated/float64_t.hlsl

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace hlsl
9090
}
9191

9292
// arithmetic operators
93-
this_t operator+(const emulated_float64_t rhs) NBL_CONST_MEMBER_FUNC
93+
this_t operator+(const this_t rhs) NBL_CONST_MEMBER_FUNC
9494
{
9595
if (FlushDenormToZero)
9696
{
@@ -150,6 +150,9 @@ namespace hlsl
150150
uint64_t resultMantissa;
151151
if (lhsSign != rhsSign)
152152
{
153+
if ((data | ieee754::traits<float64_t>::signMask) == (rhs.data | ieee754::traits<float64_t>::signMask))
154+
return _static_cast<this_t>(0ull);
155+
153156
uint64_t rhsNormMantissaHigh = shiftAmount >= 64 ? 0ull : rhsNormMantissa >> shiftAmount;
154157
uint64_t rhsNormMantissaLow = 0ull;
155158
if (shiftAmount < 128)
@@ -197,25 +200,25 @@ namespace hlsl
197200
return bit_cast<this_t>(0xdeadbeefbadcaffeull);
198201
}
199202

200-
emulated_float64_t operator+(float rhs)
203+
this_t operator+(float rhs)
201204
{
202205
return bit_cast<this_t>(data) + create(rhs);
203206
}
204207

205-
emulated_float64_t operator-(emulated_float64_t rhs) NBL_CONST_MEMBER_FUNC
208+
this_t operator-(this_t rhs) NBL_CONST_MEMBER_FUNC
206209
{
207-
emulated_float64_t lhs = bit_cast<this_t>(data);
208-
emulated_float64_t rhsFlipped = rhs.flipSign();
210+
this_t lhs = bit_cast<this_t>(data);
211+
this_t rhsFlipped = rhs.flipSign();
209212

210213
return lhs + rhsFlipped;
211214
}
212215

213-
emulated_float64_t operator-(float rhs) NBL_CONST_MEMBER_FUNC
216+
this_t operator-(float rhs) NBL_CONST_MEMBER_FUNC
214217
{
215218
return bit_cast<this_t>(data) - create(rhs);
216219
}
217220

218-
emulated_float64_t operator*(emulated_float64_t rhs) NBL_CONST_MEMBER_FUNC
221+
this_t operator*(this_t rhs) NBL_CONST_MEMBER_FUNC
219222
{
220223
if(FlushDenormToZero)
221224
{
@@ -233,7 +236,7 @@ namespace hlsl
233236
if (emulated_float64_t_impl::isZero(data) || emulated_float64_t_impl::isZero(rhs.data))
234237
return bit_cast<this_t>(sign);
235238

236-
emulated_float64_t retval = this_t::create(0ull);
239+
this_t retval = this_t::create(0ull);
237240

238241
int lhsBiasedExp = ieee754::extractBiasedExponent(data);
239242
int rhsBiasedExp = ieee754::extractBiasedExponent(rhs.data);
@@ -269,12 +272,12 @@ namespace hlsl
269272
}
270273
}
271274

272-
emulated_float64_t operator*(float rhs)
275+
this_t operator*(float rhs)
273276
{
274277
return bit_cast<this_t>(data) * create(rhs);
275278
}
276279

277-
emulated_float64_t operator/(const emulated_float64_t rhs) NBL_CONST_MEMBER_FUNC
280+
this_t operator/(const this_t rhs) NBL_CONST_MEMBER_FUNC
278281
{
279282
if (FlushDenormToZero)
280283
{
@@ -332,7 +335,7 @@ namespace hlsl
332335
}
333336
}
334337

335-
emulated_float64_t operator/(const float rhs) NBL_CONST_MEMBER_FUNC
338+
this_t operator/(const float rhs) NBL_CONST_MEMBER_FUNC
336339
{
337340
return bit_cast<this_t>(data) / create(rhs);
338341
}
@@ -350,37 +353,37 @@ namespace hlsl
350353

351354
return data == rhs.data;
352355
}
353-
bool operator!=(emulated_float64_t rhs) NBL_CONST_MEMBER_FUNC
356+
bool operator!=(this_t rhs) NBL_CONST_MEMBER_FUNC
354357
{
355358
if (!FastMath && (hlsl::isnan<uint64_t>(data) || hlsl::isnan<uint64_t>(rhs.data)))
356359
return false;
357360

358361
return !(bit_cast<this_t>(data) == rhs);
359362
}
360-
bool operator<(emulated_float64_t rhs) NBL_CONST_MEMBER_FUNC
363+
bool operator<(this_t rhs) NBL_CONST_MEMBER_FUNC
361364
{
362365
return emulated_float64_t_impl::operatorLessAndGreaterCommonImplementation<FastMath, hlsl::less<uint64_t> >(data, rhs.data);
363366
}
364-
bool operator>(emulated_float64_t rhs) NBL_CONST_MEMBER_FUNC
367+
bool operator>(this_t rhs) NBL_CONST_MEMBER_FUNC
365368
{
366369
return emulated_float64_t_impl::operatorLessAndGreaterCommonImplementation<FastMath, hlsl::greater<uint64_t> >(data, rhs.data);
367370
}
368-
bool operator<=(emulated_float64_t rhs) NBL_CONST_MEMBER_FUNC
371+
bool operator<=(this_t rhs) NBL_CONST_MEMBER_FUNC
369372
{
370373
if (!FastMath && (hlsl::isnan<uint64_t>(data) || hlsl::isnan<uint64_t>(rhs.data)))
371374
return false;
372375

373376
return !(bit_cast<this_t>(data) > bit_cast<this_t>(rhs.data));
374377
}
375-
bool operator>=(emulated_float64_t rhs)
378+
bool operator>=(this_t rhs)
376379
{
377380
if (!FastMath && (hlsl::isnan<uint64_t>(data) || hlsl::isnan<uint64_t>(rhs.data)))
378381
return false;
379382

380383
return !(bit_cast<this_t>(data) < bit_cast<this_t>(rhs.data));
381384
}
382385

383-
emulated_float64_t flipSign()
386+
this_t flipSign()
384387
{
385388
return bit_cast<this_t>(data ^ ieee754::traits<float64_t>::signMask);
386389
}

include/nbl/builtin/hlsl/emulated/float64_t_impl.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ inline uint64_t castFloat32ToStorageType(float32_t val)
7575

7676
NBL_CONSTEXPR_INLINE_FUNC bool isZero(uint64_t val)
7777
{
78-
return (val << 1) == 0;
78+
return (val << 1) == 0ull;
7979
}
8080

8181
inline uint64_t reinterpretAsFloat64BitPattern(uint64_t val)

0 commit comments

Comments
 (0)