Math Library compatible with full .NET
I’m very busy building my Dare To Dream Different Challenge project. As this is a contest it’s hard to decide what to publish and what not. For my project I need a fair amount of mathematical functions like Sin, Cos, Tan, Exp, etc. These are not implemented, or in the case of Sin and Cos very inaccurate in .NET Micro Framework.
So I started the search how to calculate those functions. I made a class of it. It’s made to be a drop-in replacement for System.Math. I tried to make it as accurate as the full .NET version.
Currently supported functions:
- double Abs(double x)
- Acos(double x)
- Asin(double x)
- Atan(double x)
- Atan2(double y, double x)
- Ceiling(double x)
- Cos(double x)
- Cosh(double x)
- Exp(double x)
- Pow(double x, double y)
- Floor(double x)
- Log(double x)
- Log(double x, double newBase)
- Log10(double x)
- Max(double x, double y)
- Min(double x, double y)
- Sinh(double x)
- Sign(double x)
- Sin(double x)
- Sqrt(double x)
- Tan(double x)
- Tanh(double x)
- Truncate(double x)
You can download the Classfile here: exMath.cs
what is your project ?
Hi Snupi,
As it is an challenge I’m keeping the idea itself secret until march. But I’ll try to post as much code examples as posible
Thanks for your class! I find project Mono a good reference for missing .Net Micro functionality.
@Jeroen: Thanks that is a good tip!
hi
could you provide the location where you find the calculations (implementation)
found something on http://www.koders.com/c/fid668AA602507232FB9BF8DF177A26CC8976024E3F.aspx?s=zreturn or http://forum.unidev.com.br/phpbb2/viewtopic.php?t=43347
thx for help
Ofcourse,
The Sin, Cos, Tan functions found on:
http://www.ganssle.com/approx/approx.pdf
The Log, Log10 on:
http://en.literateprograms.org/Logarithm_Function_%28Python%29
Information about IEEE754 Floating point:
http://www.radiks.net/~rhuebner/mathlib.html
The rest is written by looking at the BSD Unix source and Wikipedia
Hi Elze,
thanks a lot for your code. But I found that the Atan2() method is buggy. To me it looks like the x and y parameters are swapped.
Could you pls. verify that?
Thanks,
Chris
Hi Chris,
Thanks I will look into it. If so I will update the class.
Kind regards,
Elze