In C, in float.h, I have :
#define FLT_MAX 3.402823466e+38F // max value
same thing in C# :
public float FLT_MAX = 3.402823466e+38F;
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have the following 2 lines of code in c
1) #define FLT_EPSILON 0x1p-23
2) #define FLT_MAX 0x1.fffffep+127
The first line can be converted to C# as follows without any syntax errors:
However, I'm struggling with (2). I'm aware of things like Float.MaxValue etc.. but is there a way to express it to closely resemble the c code? Its basically expressing floating point values in hex format unless Im mistaken.
2) #define FLT_MAX 0x1.fffffep+127
In C, in float.h, I have :
#define FLT_MAX 3.402823466e+38F // max value
same thing in C# :
public float FLT_MAX = 3.402823466e+38F;
Floating point number are in binary. This translates to hex fine, but there are precision errors when decimal is used. This why hex was added to c.
You should use the defined min, max and epsilon values in c#
https://learn.microsoft.com/en-us/dotnet/api/system.single.epsilon?view=net-7.0
which the compiler guarantees will be the correct binary values.