bah.mapm

BlitzMax Forums/Brucey's Modules/bah.mapm

Artemis(Posted 2008) [#1]
Hi,

in this module there is the method
	Method SinCos(_sin:TMAPM, _cos:TMAPM, decimalPlaces:Int)


Shouldn't it be
	Method SinCos(_sin:TMAPM Var, _cos:TMAPM Var, decimalPlaces:Int)

?


Artemis(Posted 2008) [#2]
Another thing which I've found an which makes me doubtful is the output of the following code:
SuperStrict

Framework BaH.MAPM
Import BRL.StandardIO

Const L:Int = 32

Local value:TMAPM = New TMAPM.Create("45")

Local sine:TMAPM = value.Sin(L)
Local cosine:TMAPM = value.Cos(L)

Print sine.ToFixtPtString(L)
Print cosine.ToFixtPtString(L)
Print sine.compare(cosine)


which outputs

0.70710678118654765902290160974513
0.70710678118654738977878711446454
1


The output is not correct because sin(45) equals cos(45).

And if I take the results of "PowerToy Calc" (enhanced calculator by Microsoft) they both are
0.70710678118654752440084436210485


If you now compare the results it shows that the numbers (bmax and powertoy calc) equal until the 15th decimal place.

Is it a bug in MAPM or in the BlitzMax-Implementation? I think it's MAPM because when looking through the code I found nothing weird which could cause this bug.


Dreamora(Posted 2008) [#3]
Don't use max precision. PowerToy Calc etc don't work with system floats / doubles but alternative implementations.
float / double is always approximative.

float is usefull up to 5 - 7 decimals behind ., double logically the double of it.

so, everything after 0.707106781186547389 is pure approximative and can (and most likely will) be false


Artemis(Posted 2008) [#4]
Sorry I don't get what you mean.

Do you mean, that Powertoy Calc gives me wrong values?

I think this bug in MAPM might be based on the algorithm used by MAPM because multiplying and dividing with a precision of 512 decimal places work correctly.


Brucey(Posted 2008) [#5]
Fear not :-)

SuperStrict
Framework BaH.MAPM
Import BRL.StandardIO
Import BRL.Math

Local angle:TMAPM = New TMAPM.Create("45")

Local sine:TMAPM = New TMAPM
Local cosine:TMAPM = New TMAPM

angle.SinCos(sine, cosine, 32)

Print "Sine   = " + sine.ToString()
Print "Cosine = " + cosine.ToString()

Now produces this :
Sine   = 0.707106781186547524400844362104849
Cosine = 0.707106781186547524400844362104849

The problem was my internal RadToDeg and DegToRad multipliers were only 16 digits accurate. So, I've now made them 520 digit accurate which will improve the math to that precision if desired.

If you wanted to increase it further, you could recalc the two multipliers (they are Global variables) to the accuracy you desire.

Otherwise, MAPM should work with number up to 2^31 digits, although I don't have enough RAM to test that :-p


Brucey(Posted 2008) [#6]
That latest revision also allows you to create an empty value with "New TMAPM", which makes for cleaner code, I think.

Method docs are complete.. but there probably needs some more general "usage" and example documentation :-)


Artemis(Posted 2008) [#7]
Thanks Brucey.

And I was wondering why some projects use MAPM while it has bugs. But now I can blame Brucey for all of it. }:->


Dreamora(Posted 2008) [#8]
hehe
As long as he, who is under control of the module and SVN, does not svn blame back ^^


Brucey(Posted 2008) [#9]
;-)