Author Topic: I feel like I'm going out of my mind  (Read 2542 times)

0 Members and 1 Guest are viewing this topic.

Offline Bert22306

  • Forum Regular
  • Posts: 206
    • View Profile
I feel like I'm going out of my mind
« on: March 01, 2021, 05:35:18 am »
Surely, this trivial program should be giving the same result, for x, y, and  z??

Code: [Select]
Screen _NewImage(120, 43, 0)
For i = 1 To 10
    x = 15 * i / 3000
    y = i / 3000 / 15
    z = i / (3000 / 15)
    Print x, y, z
Next i
End

Was going bonkers trying to debug something, and the problem came down to the above, when distilled to its basics. What am I forgetting? Thanks!
« Last Edit: March 01, 2021, 05:37:01 am by Bert22306 »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: I feel like I'm going out of my mind
« Reply #1 on: March 01, 2021, 06:22:34 am »
Forgetting basic math?

1 / 2 / 3 isn't the same as 3 * 1 / 2....

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(120, 43, 0)
  2. FOR i = 1 TO 10
  3.     x = 15 * i / 3000
  4.     y = i / 3000 * 15
  5.     z = i / (3000 / 15)
  6.     PRINT x, y, z
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Bert22306

  • Forum Regular
  • Posts: 206
    • View Profile
Re: I feel like I'm going out of my mind
« Reply #2 on: March 01, 2021, 07:21:28 am »
Forgetting something, for sure. Best to be generous with parentheses. Thanks, Steve!

It was a case of, 1 / 2 / 3 is not the same as 1 / (2 / 3)

In fact, 1 / (2 / 3) is the same as 3 * 1 / 2.

That was my issue.
« Last Edit: March 01, 2021, 07:32:28 am by Bert22306 »