You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ESP32-S3 has a hardware single-precision FPU, but the following code produces unexpected results. I believe these methods could be effectively implementable using integers, even without the FPU. Additionally, I am confused about the floating-point model in nanoFramework. Should it adhere to the IEEE 754 standard?
I have found code that appears to correctly compare floating point numbers. However, this code is guarded by certain macros.
//--//
#if !defined(NANOCLR_EMULATED_FLOATINGPOINT)
case DATATYPE_R4:
// deal with special cases:// return 0 if the numbers are unordered (either or both are NaN)// this is post processed in interpreter so '1' will turn into '0'if (__isnand(left.NumericByRefConst().r4) && __isnand(right.NumericByRefConst().r4))
{
return1;
}
// The infinite values are equal to themselves.// this is post processed in interpreter so '0' will turn into '1'elseif (__isinfd(left.NumericByRefConst().r4) && __isinfd(right.NumericByRefConst().r4))
{
return0;
}
// all the rest nowelse
{
if (isgreater(left.NumericByRefConst().r4, right.NumericByRefConst().r4))
{
return1;
}
elseif (isless(left.NumericByRefConst().r4, right.NumericByRefConst().r4))
{
return -1;
}
else
{
return0;
}
}
case DATATYPE_R8:
// deal with special cases:// return 0 if the numbers are unordered (either or both are NaN)// this is post processed in interpreter so '1' will turn into '0'if (__isnand((double)left.NumericByRefConst().r8) || __isnand((double)right.NumericByRefConst().r8))
{
return1;
}
// The infinite values are equal to themselves.// this is post processed in interpreter so '0' will turn into '1'elseif (
__isinfd((double)left.NumericByRefConst().r8) && __isinfd((double)right.NumericByRefConst().r8))
{
return0;
}
// all the rest nowelse
{
if (isgreater((double)left.NumericByRefConst().r8, (double)right.NumericByRefConst().r8))
{
return1;
}
elseif (isless((double)left.NumericByRefConst().r8, (double)right.NumericByRefConst().r8))
{
return -1;
}
else
{
return0;
}
}
#elsecase DATATYPE_R4:
case DATATYPE_R8:
fSigned = true;
#endif
The text was updated successfully, but these errors were encountered:
Short answer: it all depends on the native side support of floating point. We're just using those. In MCU some, if can be perfect, in some others, not. We're not rewriting this part and just use what's in each vendors SDK and chips.
Library/API/IoT binding
NF-Interpreter, CoreLibrary, Runtime.Native
Visual Studio version
No response
.NET nanoFramework extension version
No response
Target name(s)
ESP32-S3
Firmware version
No response
Device capabilities
No response
Description
The ESP32-S3 has a hardware single-precision FPU, but the following code produces unexpected results. I believe these methods could be effectively implementable using integers, even without the FPU. Additionally, I am confused about the floating-point model in nanoFramework. Should it adhere to the IEEE 754 standard?
How to reproduce
Outputs
1 == FloatingPoint.SinglePrecisionSoftware
Expected behaviour
3 == FloatingPoint.SinglePrecisionHardware
Screenshots
No response
Sample project or code
No response
Aditional information
I have found code that appears to correctly compare floating point numbers. However, this code is guarded by certain macros.
The text was updated successfully, but these errors were encountered: