Any Decent Math Library Available?

Any update on the location of that math library? :smiley: <- this guy desperately needs it.

The Mayh libary is located under

GHIElectronics.NETMF.System Namespace ā†’ Math Ex

See here for more information

http://www.ghielectronics.com/downloads/NETMF/Library%20Documentation/Index.html

Hope this helps

BR

Cypher

Is it possible to use the GHI Premium math library on the new Mountaineer Board? Will it perform better on the STM43F4 chip with its onboard DSP?

Cheers,

Steve

No, it is not possible.

What math functions do you need specifically?

I am interested in simple trig functions such as Sin, and Cos, with double precision. I am investigating the performance of the exMath class written by Elze ( http://www.microframework.nl/2009/01/15/math-library-compatible-with-full-net/ ). Any other thoughts or suggestions?

I found a few bugs in Elzeā€™s trig functions. He hasnā€™t updated it in a very long time. You can find my fixed version here as NETMFx.Math:

http://netmfx.codeplex.com/

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.

@ Gus - Hi Gus,
I have a question, I want to round a double variable (0.71999999996 to 0.72), but when the syntax incode as in the following image.

When I remove the number 2, the error disappears but the rounding is a int
can you tell me please, how I do the rounding? or my error please?

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.

@ Brett -
Thanks Brett
but which is the way to get as a result only 2 decimal places? can you tell me please?

to two decimal places? multiply by 100 then divide rounded result by 100.

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.


static double RoundTo2Decimals(double value)
{
    return System.Math.Round(value * 100) / 100.0;
}

@ taylorza -
Thanks Taylorza and Brett!
I will use the method of Taylorza because I will show the valor in a display.

@ 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.

@ andre.m -
Thanks Andre, I will do it.