3

I am currently translating a program from QBasic to VB.Net and I have this line of code :

RSA = 270 + 180 / PI * (ATN(ABS(X(Z, 2) / X(Z, 1))))

I translated it as

RSA = 270 + 180 / PI * (Math.Atan(Math.Abs(arrayX(z - 1, 2 - 1) / arrayX(z - 1, 1 - 1))))

for VB.Net but the results are different. Here are some informations :

PI = 3.141592654

And for my test
I used "6.8929106501697825" for my X(Z, 2) value
I used "-5.08864764726704" for my X(Z, 1) value

The result for QBasic is : 323.9964
The result for VB.Net is : 323.5636369944437

Did I do something wrong?

Thanks

Mark Hall
  • 53,938
  • 9
  • 94
  • 111
Holytoutant
  • 51
  • 1
  • 6
  • 2
    You got the right result for the input data you have. My guess is when you filled in your array you didn't do the same correction from 1 to 0 base offset. Verify that the input data in QBasic and VB.NET is the same. – Aleks Feb 22 '12 at 02:10
  • Then maybe QBasic being very old by now is using lookup tables to compute atn therefore makes some rounding. Although having almost half degree error is hard to believe – Aleks Feb 23 '12 at 23:26

2 Answers2

3

I suspect you're running into an old-fashioned 16-bit limitation of QBasic.

Way back when dinosaurs walked the earth, and people used single precision floating point math in QBasic, they knew that the variable would only store 7 significant figures.

So if your QBasic data types are singles, then regardless of what you believe you entered, in QBasic they'll actually be:

PI = 3.141592
X(Z, 2) = 6.892910
X(Z, 1) = -5.088647
Derek Tomes
  • 3,989
  • 3
  • 27
  • 41
2

I just leanrned that there is no problem in my calculation. The reason why the result is different is just because Visual Basic is more precise so my calculation is just more accurate.

Thanks a lot for answers!

Holytoutant
  • 51
  • 1
  • 6