Another common solution is to use lookup tables. Thatās actually a much faster solution if youāre doing a lot of math. I have another possible solution in the works but I just started on it last weekend and itāll probably be a few months before itās ready if it proves to be worthwhile at all. Iād start with the math lib and see if thatās good enough. Your other alternative is to write some RLPLite functions.
I looked at using lookup tables for Sin, Cos and Tan functions, however it was more efficient to complete the Math operation than incur the overhead of accessing the lookup array.
Interesting. This is opposite from what Iāve heard from others. I think GHI uses lookup tables for their premium functions. Perhaps itās the difference between managed vs. unmanaged.
I can confirm this, but it should be seen in context. Calling a native math function outperforms the .NETMF lmanaged code implementation since it takes more cycles to interpret the managed code and perform the lookup. In native code this will not be the case ESP. For trig functions.
Although the online documentation doesnāt show it (Math Members | Microsoft Learn), I noticed the System.Math class in .NET MF 4.2 is almost the same as in the full .NET, including double precision trigonometry functions.
The error is that there is no second parameter in the ROUND method of system.math. You can see the description of Round() in the MSDN page Math Members | Microsoft Learn that says, explicitly, āRounds a double-precision floating-point value to the nearest integerā.
You could āfakeā this by multiplying by 10 first, then dividing by 10.
The question is, do you need this for calculation purposes or for display purposes?
If you need it for display purposes then you can use ToString() like this
double x = 123.546234;
string strX = x.ToString("f2");
If you actually want to round for calculation purposes then the functions below should do the trick for you.
Here is a generic function that can be used to round to any arbitrary number of fractional digits.
static double Round(double value, int digits)
{
if (digits < 0 || digits > 15)
{
throw new ArgumentOutOfRangeException("Rounding digits must be between 0 and 15, inclusive.");
}
double scale = System.Math.Pow(10, digits);
return System.Math.Round(value * scale) / scale;
}
If you need better performance and you know that you want to round to only 2 digits after the decimal point then you can go with an optimized version of the above code.
@ taylorza -
Hi Taylorza and Brett,
Im working with to LCD sparkfun https://www.sparkfun.com/products/9351
I searched all day,como cambiar la configuracion de la lcd para mostrar los caracteres de tamaƱo mayor al de default.
I hope you can help me please?
Tanks,greetings.
@ Brett -
Hi Taylorza and Brett,
Im working with to LCD sparkfun https://www.sparkfun.com/products/9351
I searched all day,como cambiar la configuracion de la lcd para mostrar los caracteres de tamaƱo mayor al de default.
I hope you can help me please?
Tanks,greetings.