Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Double prescision math lib?


  • Please log in to reply
38 replies to this topic

#21 Fabien Royer

Fabien Royer

    Advanced Member

  • Members
  • PipPipPip
  • 406 posts
  • LocationRedmond, WA

Posted 27 April 2011 - 09:01 PM

I have published another solution that would be appreciable for Netduino users.


Thanks Mario!
I'll incorporate your alternative algorithm into the library.

Cheers,
-Fabien.

#22 KodeDaemon

KodeDaemon

    Advanced Member

  • Members
  • PipPipPip
  • 63 posts

Posted 28 April 2011 - 12:06 AM

I was not aware that you wrote one. Got a link? Does it require reflashing the netduino with a custom firmware?

-Fabien.


It does require a custom firmware. If we can get enough people interested maybe we can get it into the main line firmware at some point. But due to the lack of interest I doubt there is much motivation to get it there.

#23 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 28 April 2011 - 12:12 AM

It does require a custom firmware. If we can get enough people interested maybe we can get it into the main line firmware at some point. But due to the lack of interest I doubt there is much motivation to get it there.


I wantz! i need sin and cos to convert polar to rectangular. *10 on adding to the official firmware

#24 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 28 April 2011 - 04:27 AM

I am sorry for the delay, but I would answer to KodeDeamon. I didn't realize that were you behind the exMath library. I have not tested all your functions, and I have tried only the square root, because I need for a FFT. That algorithm gives a good result, until the argument is relatively small. If you try to calculate the square root of 1E6 or greater, the function takes seconds (even minutes) also on a PC. Double vs float. I have not a strong experience with MF, but since this is a Netduino-forum (not a 180MHz GHI ChipworkX), I have realized that every line of C# should be handled with care. That for a decent performance. I was surprised by the float perf compared to the integers: floats are slightly slower than ints. That is a very good new. Doubles are better in general, but they takes double memory and easily make the program running much slower. For this reason, I'd provide float-based functions, instead of double-based. On your source there are a lot of float-double casts without reason. Just now I have noticed that Fabien changed the sources so that they are float only. That only to point *why* I have answered about some part of the exMath lib. Your effort is anyway really appreciable. Thanks for sharing. Cheers
Biggest fault of Netduino? It runs by electricity.

#25 KodeDaemon

KodeDaemon

    Advanced Member

  • Members
  • PipPipPip
  • 63 posts

Posted 28 April 2011 - 06:10 AM

I am sorry for the delay, but I would answer to KodeDeamon.
I didn't realize that were you behind the exMath library.

I have not tested all your functions, and I have tried only the square root, because I need for a FFT. That algorithm gives a good result, until the argument is relatively small. If you try to calculate the square root of 1E6 or greater, the function takes seconds (even minutes) also on a PC.

Double vs float. I have not a strong experience with MF, but since this is a Netduino-forum (not a 180MHz GHI ChipworkX), I have realized that every line of C# should be handled with care. That for a decent performance.
I was surprised by the float perf compared to the integers: floats are slightly slower than ints. That is a very good new.
Doubles are better in general, but they takes double memory and easily make the program running much slower. For this reason, I'd provide float-based functions, instead of double-based.
On your source there are a lot of float-double casts without reason.
Just now I have noticed that Fabien changed the sources so that they are float only.

That only to point *why* I have answered about some part of the exMath lib. Your effort is anyway really appreciable.
Thanks for sharing.
Cheers


I'm not really sure who you are directing these comments to. exMath is not my math library. The math library I have contributed is a native code implementation of many of the standard math functions. I tried to mirror the methods available in the full .net framework as best as I could base on what was available in the libraries RVDS provided.

The following are the currently supported method calls; the signatures are identical to their full framework counterparts (all of which are implemented in native code):

double Acos(double d)
double Asin(double d)
double Atan(double d)
double Atan2(double y, double x)
double Ceiling(double a)
double Cos(double d)
double Cosh(double value)
double Exp(double d)
double Floor(double d)
double Log(double d)
double Log10(double d)
double Pow(double x, double y)
double Sin(double a)
double Sinh(double value)
double Sqrt(double d)
double Tan(double a)
double Tanh(double value)

#26 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 28 April 2011 - 08:11 AM

OK, I am completely off my mind. I am sorry for that. I was thinking you were the author of the exMath. The consideration about the square-root is still valid, though. About the double perf using native code, have you any comparison to show us? Cheers
Biggest fault of Netduino? It runs by electricity.

#27 Jon Henry

Jon Henry

    Advanced Member

  • Members
  • PipPipPip
  • 43 posts

Posted 28 April 2011 - 12:41 PM

Kodedaemon, Would you happen to have a build for 4.1.1.0 Alpha 7?

#28 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 28 April 2011 - 01:47 PM

It got me thinking ... We should have an application that is PC based, that talks to a netduino through IP. The PC version would display the difference (3 columns, one for the selected function PC result, one for the Netduino result and one for the differences) for input many values for a selected function (have a combobox with all the available function) (2 more columns for the time it took ?) The PC application would poll the netduino for a series of results from a given function and a given series of input values, and then display them on screen. This would allow to show the valid ranges of some functions (we do that in physics) and the cost of using them (FFT you need something fast no ?). It would also allow the library coders see the results of their implementation on the spot :) Web server on the netduino plus, PC app that talks to the netduino server showing columns (I need to learn how to do all that lol) It would be a great application for anyone that wants to use the netduino for science ... they would know right there and then what would be the cost and errors induced by using the netduino. I vote for this as a tutorial :) Anyone interested ?
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#29 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 28 April 2011 - 02:00 PM

Michel, I really can't understand what you are going to propose and for what target...
Biggest fault of Netduino? It runs by electricity.

#30 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 28 April 2011 - 02:41 PM

Michel, I really can't understand what you are going to propose and for what target...

I propose to build a tutorial that would have a good side effect : show the differences between the math libraries on the netduino and the ones on the PC.

It would do many simple things :

1- show how to create a web server on the netduino (a sample already exist so we can use that)
2- show how to interact with that web server from a pc (the sample does already show that)
3- show the simplest form of table data display on the pc (i need to learn how to do that)
4- show how to timestamp data results to get processing time on the netduino and on the pc (I also need to learn that)
5- show what math functions are available on the netduino and
6- show the induced errors of those functions in certain input value ranges (needed when doing complex mathematical algorithm) on the netduino
7- show the time cost of using certain mathematical functions with certain input value ranges

Anyone interested in using the complex mathematical functions on the netduino should be made aware of the induced errors with certain input ranges of some functions and the time cost of using those functions in their netduino application.

That is the goal I want to attain. Inform of the errors and cost of each mathematical functions available on the netduino, and teach a thing or two while doing it (like tabular data display on the PC) !
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#31 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 28 April 2011 - 03:03 PM

Okay, I have realized. But why do you thinking to a web server? The cost of a certain function (e.g. Sin) is a constant, especially on a very stable board like Netduino. The actual time spent for a complex task involving more computations would be sensible of other threads, so that cannot established once for all. Anyway, I am just testing the Sin/Cos function included in the exMath. I guess that should be changed because it gives a wrong error for arguments outside [-PI..+PI]. I am trying to see a better way to calculate them. Cheers
Biggest fault of Netduino? It runs by electricity.

#32 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 28 April 2011 - 03:35 PM

But why do you thinking to a web server?

To show the results on a PC ... live !

And the timestamp would mark the begining and end of the call on the netduino to the math function (for the netduino values).

The webserver would receive a function to test and a series of values to use. For each value to test the function with, a timestamp is used to calculate the number of ticks needed to execute it (some input values might take longer to calculate the output than others). It would reply with a table of data to display on the PC side by side the PC calculated equivalent sent to the netduino to compare :)

We could even show the values graphically (I do need to learn how to do that too, lol)
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#33 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 28 April 2011 - 03:49 PM

At home I have a ready-to-use basis for Netduino Plus (SD+ETH needed) and Silverlight on PC. The SL page polls the N+ every sec asking for data. The N+ web-server answers back to the page, finally the data is both graphically and tabled. Is that what you are looking for? I may send both the solutions (one for N+ the other for SL), but you should manage this kind of project, because I have no time! Cheers
Biggest fault of Netduino? It runs by electricity.

#34 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 28 April 2011 - 03:57 PM

At home I have a ready-to-use basis for Netduino Plus (SD+ETH needed) and Silverlight on PC.
The SL page polls the N+ every sec asking for data. The N+ web-server answers back to the page, finally the data is both graphically and tabled.
Is that what you are looking for?

I don't have a netduino plus yet nor do I have a ethernet shield but yes, this is exactly what I'm looking for as a frame for this mathematical tutorial ! That would be a great start ! I could probably do the missing code even without ethernet connection (using debug.print lol).

YES ME WANT :) Please !

Put it in a new project showcase and I'll grab it from there ! Or in the wiki ? Your choice !

Boy do I love this community !
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#35 KodeDaemon

KodeDaemon

    Advanced Member

  • Members
  • PipPipPip
  • 63 posts

Posted 28 April 2011 - 09:33 PM

Kodedaemon,

Would you happen to have a build for 4.1.1.0 Alpha 7?


I will have to see if I can get a build cooked up for you. Which Netduino do you have?

#36 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 28 April 2011 - 11:18 PM

I will have to see if I can get a build cooked up for you. Which Netduino do you have?

Normal Netduino for me ! Will need the Netduino plus to test it live with the webserver app that Mario put on the forums that I need to modify for this purpose :) (Thanks Mario)
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#37 Jon Henry

Jon Henry

    Advanced Member

  • Members
  • PipPipPip
  • 43 posts

Posted 30 April 2011 - 04:07 AM

Just the plain old netduino kodedaemon. Thanks

#38 CodeRage

CodeRage

    New Member

  • Members
  • Pip
  • 8 posts

Posted 04 May 2011 - 12:18 AM

KodeDaemon, Sorry bud, I wasnt aware you had another option out there. After much searching I couldn't fine anything other than exMath. It worked but it is ungodly slow for the calculations I am performing. For now I had to port it to my desktop to do all the major number crunching and then moved the results to the netduino plus. I would eagerly test anything you could provide.

#39 CodeRage

CodeRage

    New Member

  • Members
  • Pip
  • 8 posts

Posted 04 May 2011 - 12:30 AM

KodeDameon, Found the firmware that was posted in the other thread. will definitely be giving it a go this weekend! Thanks for making them available.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.