Go Down

Topic: MathHelpers - library for representing scientific notation (and some more) (Read 152 times) previous topic - next topic


Long ago I wrote several misc. Math Helper functions. I put the ones I used most often in a small library so other people can use them too.

Most important function is char * sci( float f, int digits); which represents a float in scientific format. Currently Serial.println(f) gives an overflow if abs(f) > MAXLONG or so. The function dtostrf() does not overflow but give ridiculous long strings.

small example, energy of a mass of 75 Kg

Code: (snippet) [Select]
float c = 2.99792458E8;      // speed of light;
float m = 7.5E5;             // 75 Kg
float E = m * c * c;         // According to Einstein

Serial.println(sci(E, 4));   // prints 6.7407E+22

Code can be found on Github
- https://github.com/RobTillaart/Arduino/tree/master/libraries/MathHelpers

As allways comments, remarks, improvements or examples  are welcome
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up