Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 00:26 27 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : variables

Author Message
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 07:27pm 18 Jan 2013
Copy link to clipboard 
Print this post

From the manual
"Numbers are stored and manipulated as single precision floating point numbers. The maximum number that can be represented is 3.40282347e+38 and the minimum is
1.17549435e-38."
When I load a variable with a number say 30.8967777 it is truncated to four decimal places. This would be affecting the accuracy of my calculations.
Am I correct.

Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 09:15pm 18 Jan 2013
Copy link to clipboard 
Print this post

MMBasic on the Maximite uses a binary32 IEEE-754 compliant single precision floating point format. See this link for more details: http://en.wikipedia.org/wiki/IEEE_floating_point

This format has a precision of just over 7 decimal digits but in practice this varies a little depending on the exact number. For example 12.34567 will retain all 7 digits when stored and printed while 34.56789 will be stored as just 6 digits.

The bottom line is that you can only trust the accuracy to be retained to 6 digits.

Geoff
Geoff Graham - http://geoffg.net
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 10:16pm 18 Jan 2013
Copy link to clipboard 
Print this post

Hmmm. Don't know what that will do to the accuracy of my GPS as .0001 degree is equivalent to about 11 metres at the equator, a bit less at this latitude.

Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3802
Posted: 03:22am 19 Jan 2013
Copy link to clipboard 
Print this post

There's a library for bigger numbers I think, and hopefully also gives more precision (which is what you're after).

Simple maths allows you to work out what the IEEE will do, if you think of every number being
x+e
where x is what you really wanted to store and e is the error (may be positive or negative).

I dimly recall this is known as error analysis but its rules are easily worked out with just a bit of thought.

Most people just live with the inaccuracies LOL

John
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2350
Posted: 04:10am 19 Jan 2013
Copy link to clipboard 
Print this post

how about keeping each value stored in two variables - the first being the number of minutes (an integer ranging from 0 to 21599 or +/-10800) and the second the number of seconds that will then have four decimal places for fractions of a second.

you can then use a simple bit of code to put the two parts together for displaying the output on screen.
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 09:09am 19 Jan 2013
Copy link to clipboard 
Print this post

Brilliant idea Robert, we never think of the easy solutions.
Thanks
Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 09:21am 19 Jan 2013
Copy link to clipboard 
Print this post

Just thought again, The formula is a bit complex;
D = R*sqr((Dlat^2)+(cos(Mlat)*(Dlon^2)))
where Dlat is the difference in latitude and Mlat is the mean latitude Dlon is the difference in longtitude.
Don't know if I can separate the values, will have to work on it.
Paul
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 09:43am 19 Jan 2013
Copy link to clipboard 
Print this post

What does this formula do?
I first thought it was for calculating the distance between to points, but my formula for that looks much different. :)

Microblocks. Build with logic.
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 12:02pm 19 Jan 2013
Copy link to clipboard 
Print this post

You are probably thinking of the formula to find the distance between two points on a graph using the pythagorean theorem. This works on a flat surface.
The formula for two coordinates is different in that we are working with a sphere, as we travel further north or south the distance between two longitudes of the same value varies, until we arrive at the poles where it would be zero.
Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 12:49pm 19 Jan 2013
Copy link to clipboard 
Print this post

I use this formula (in C#), it's the http://en.wikipedia.org/wiki/Haversine_formula :

int Radius = 6371; // earth's mean radius in km
double Distance = Math.Acos(Math.Sin(current.Latitude * 0.01745329) * Math.Sin(Previous.Latitude * 0.01745329) + Math.Cos(current.Latitude * 0.01745329) * Math.Cos(Previous.Latitude * 0.01745329) *
Math.Cos((Previous.Longitude - current.Longitude) * 0.01745329)) * Radius;

The number 0.01745329 is pi/180 to convert the values to radians.

Your formula, if it does the same looks like it will process faster, or maybe not because of the square root. That is not an easy one for a cpu.




Microblocks. Build with logic.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 01:09pm 19 Jan 2013
Copy link to clipboard 
Print this post

  palcal said   You are probably thinking of the formula to find the distance between two points on a graph using the pythagorean theorem. This works on a flat surface.
The formula for two coordinates is different in that we are working with a sphere, as we travel further north or south the distance between two longitudes of the same value varies, until we arrive at the poles where it would be zero.
Paul.

Surely a golf course is so small compared to the surface of the earth that it could be treated as a flat surface?
Geoff Graham - http://geoffg.net
 
ajkw
Senior Member

Joined: 29/06/2011
Location: Australia
Posts: 290
Posted: 01:26pm 19 Jan 2013
Copy link to clipboard 
Print this post

Your likely right Geoff but you got me thinking, how many shots would it be from say Mawson's Hut to the South Pole? You might need a fluro ball and if you play straight down a line of longitude then PalCal's MiniMM Golf GPS would do alright!
Edited by ajkw 2013-01-20
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 02:55pm 19 Jan 2013
Copy link to clipboard 
Print this post

TZAdvantage, the formula I am using is the Haversine formula, my values are in radians.

Geoff. Yes the golf course could be regarded as a flat surface. The formula to work out the distance on a graph assumes an X and Y axis and the values are distances from the axis. I don't have these distances only geographical coordinates.
I did some tests this morning and everything seems to be accurate.
Paul.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024