In C# it bugs me how there is no "Math.Cos" function that returns a float. A double is the only value you can get back thus forcing you to cast it to a float.
Like so:float val = (float)Math.Cos(someVal);
I need to use floats because i'm doing stuff in Direct3D which strictly uses floats. Floats are much more common in the graphics world(as it stands now) because they are 32bit.
Is there any functionality within C# I can use that would simply just process floats like C++ can do??
I do not want to wrap any C++ stuff because this needs to run on XNA & Linux for OpenGL.
NOTE: It would nice to have code that did not cast a double to a float.
In this case pi (3.141592653589793), has been encoded into the double precision floating point number. Note that the true value of this double precision number is 3.14159265358979311599796346854. There are multiple ways to store a decimal number in binary with a varying level of precision.
The well-known 3.14159265358979... value (Read Only). The ratio of the circumference of a circle to its diameter. Note that this value is a 32-bit floating point number i.e. a float .
Cos() is an inbuilt Math class method which returns the cosine of a given double value argument(specified angle). Parameter: num: It is the angle(measured in radian) whose cosine is to be returned and the type of this parameter is System.
Starting with .NET Core 2.0 (.NET Standard 2.1) (C# 8.0) and upper this is possible thing as built-in function.
You can just use MathF
class with built-in constants or functions working with float
type.
Example:
float cos = MathF.Cos(MathF.PI);
For further information see documentation on MSDN about MathF
type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With