Home > Just Blog'ing > Math Library compatible with full .NET

Math Library compatible with full .NET

January 15th, 2009 Elze Leave a comment Go to comments

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
 

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • NuJIJ
  • Technorati
  • Yahoo! Bookmarks
Categories: Just Blog'ing Tags: ,
  1. sanny
    January 16th, 2009 at 08:50 | #1

    what is your project ?

  2. January 16th, 2009 at 20:01 | #2

    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

  3. Jeroen
    January 17th, 2009 at 10:19 | #3

    Thanks for your class! I find project Mono a good reference for missing .Net Micro functionality.

  4. January 17th, 2009 at 19:56 | #4

    @Jeroen: Thanks that is a good tip!

  5. sanny
    January 18th, 2009 at 14:30 | #5

    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

  6. January 18th, 2009 at 15:00 | #6

    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

  7. Chris
    October 11th, 2009 at 18:27 | #7

    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

  8. Elze
    October 17th, 2009 at 12:07 | #8

    Hi Chris,

    Thanks I will look into it. If so I will update the class.

    Kind regards,

    Elze

  1. No trackbacks yet.