LOG base 10
Archiver
Posts: 46,084
has anyone written a function for calculating Log ? I found an
approximation method, but i dont know how to do floating point math
in PBASIC. here is what i am trying to do.
Using Simpson's Method to approximate y = Log(x):
'{$STAMP BS2} 'STAMP directive (specifies a BS2)
j VAR WORD
y VAR WORD
l VAR WORD
r VAR WORD
m VAR WORD
w VAR WORD
d VAR WORD
x VAR WORD
x = 2
d = 500
x = x - 1
d = 2 * d
w = x / d
FOR j = 1 TO d STEP 1
l = 1 + 2 * (j - 1) * w
r = 1 + 2 * j * w
m = (l + r) / 2
y = (w / 3) * ((1 / L) + 4 * (1 / m) + (1 / r)) + y
NEXT
y = y / 2.30258
debug ? y
i know of corse this isnt going to work because of bits and bytes and
stuff.
Any ideas ?
approximation method, but i dont know how to do floating point math
in PBASIC. here is what i am trying to do.
Using Simpson's Method to approximate y = Log(x):
'{$STAMP BS2} 'STAMP directive (specifies a BS2)
j VAR WORD
y VAR WORD
l VAR WORD
r VAR WORD
m VAR WORD
w VAR WORD
d VAR WORD
x VAR WORD
x = 2
d = 500
x = x - 1
d = 2 * d
w = x / d
FOR j = 1 TO d STEP 1
l = 1 + 2 * (j - 1) * w
r = 1 + 2 * j * w
m = (l + r) / 2
y = (w / 3) * ((1 / L) + 4 * (1 / m) + (1 / r)) + y
NEXT
y = y / 2.30258
debug ? y
i know of corse this isnt going to work because of bits and bytes and
stuff.
Any ideas ?
Comments
website, it is very quick and you can make the conversion from log
(2) to log(10) with one calculation.
Jack
--- In basicstamps@y..., "zinggzang" <danieljcyr@a...> wrote:
> has anyone written a function for calculating Log ? I found an
> approximation method, but i dont know how to do floating point
math
> in PBASIC. here is what i am trying to do.
>
> Using Simpson's Method to approximate y = Log(x):
> '{$STAMP BS2} 'STAMP directive (specifies a BS2)
>
> j VAR WORD
> y VAR WORD
> l VAR WORD
> r VAR WORD
> m VAR WORD
> w VAR WORD
> d VAR WORD
> x VAR WORD
>
> x = 2
> d = 500
>
> x = x - 1
> d = 2 * d
> w = x / d
>
> FOR j = 1 TO d STEP 1
> l = 1 + 2 * (j - 1) * w
> r = 1 + 2 * j * w
> m = (l + r) / 2
> y = (w / 3) * ((1 / L) + 4 * (1 / m) + (1 / r)) + y
> NEXT
>
> y = y / 2.30258
>
> debug ? y
>
> i know of corse this isnt going to work because of bits and bytes
and
> stuff.
> Any ideas ?