Rockbox mail archive
Subject: Re: math function for calculator
From: BlueChip (cs_bluechip_at_webtribe.net)
Date: 20040502
Try this:
V/G = N ... (G+N)/2 = G
repeat until G=N
V = Value (for which we are seeking the root)
G = most recent Guess
N = New guess
Example for root of V=12 with an arbitrary intial guess of 2
find _/12 ... guess 2.000
12/2.000 = 6.000 ... (2.000+6.000)/2 = 4.000
12/4.000 = 3.000 ... (4.000+3.000)/2 = 3.500
12/3.500 = 3.429 ... (3.500+3.429)/2 = 3.465
12/3.465 = 3.463 ... (3.465+3.463)/2 = 3.464
12/3.464 = 3.464
3.464^2 = 11.999
_/12 is irrational, so to get 12 back out of the other end you will need an
infinite number of digits after the decimal place, hence the result above
being 11.999, that is because I decided to offer a result to only 3 decimal
places.
Obviously faster methods can be found, but generally you will need to rely
on the existence of other mathematical functions (such as logn) or big
memoryhungry lookup tables  Although for this application where our app
is 32K endofstory, a lookup table of 1..2K would not be harmful.
One use of a lookup table might be to get a good initial guess...
With a table of all known integer squares:
_/105 lies somewhere between _/100 (=10) and _/121 (=11)
121  100 = 21
21 / (105100) = 4.200
(1) / 4.200 = .238
So an initial guess of 10.238 would be reasonable
The answer is actually 10.247
If you need clarification on any of that, please ask.
ChipBleu
>rb>sqrt() is not working. sqrt() is not defined in plugin API.
>It's no big deal, though. I'll just leave this function as x/2.
>
>My interface is a little complex than yours. I simulate the interface
>of the standard calculator in Windows 2k, which has backspace, memory,
>1/x, sqrt, etc. And I draw some lines and grid, too.
>
>I decided to write display part myself. Actually, I've already finished
>this part. But then I decided to rewrite the whole core code and add
>support to scientific number format.
>
>I'll post my code as soon as it's in alpha version.
>
> >tinousus_at_yahoo.com wrote:
> >> The problem I met is that: I always get error of "undefined sqrt()
> funtion" even I include math.h when
> >
> >
> >Try rb>sqrt()
> >/me was the one that was developing the other calc plugin.
> >
> >
> >If you can find any way to typecast a double to a string without the use
> >of snprintf, let me know, because I have a very basic LCD working (
> >http://kaboofa.liek.us/stuff/calcshot.png [sic] )
>
>_______________________________________________
>http://cool.haxx.se/mailman/listinfo/rockbox
_______________________________________________
http://cool.haxx.se/mailman/listinfo/rockbox
Page was last modified "Jan 10 2012" The Rockbox Crew
