Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I also have a question - about DefInt
#1
While youse guys are studying cause and effect, I've been experimenting with the DefInt function, and I don't understand the results.
The DefInt function truncates all variables of that name to their integer values, and they then operate with this integer value, right?
But why do I get the Inf result in this snippet? I guess it's to do with their binary expression? 
t1 and t2 are "simple" integers aren't they?
Code: (Select All)
DefInt T
t1 = Timer
Print "T1 is integer. ", , , t1
Sleep 2
ActOnT


Sub ActOnT
    t2 = Timer
    Print "t2 is integer in sub. ", , , t2
    t3 = t1 / t2
    Print "t3 is result of t1 divided by t2, I expect 0. ", t1 / t2
    t4 = t2 / t1
    Print "t4 is result of t2 divided by t1, I expect 1. ", t2 / t1
End Sub
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#2
Division by 0.

T1 isn't a shared variable.
Reply
#3
You're seeing the difference between `/` division and `\` division. Basically, "regular" division turns both arguments into floating-point (`DOUBLE`) values before doing the division, and the result is another floating-point value. If you pass the expression directly to `Print` then you'll be printing the resulting `DOUBLE` value.

If you instead do `t4 = t2 / t1`separately and pass `t4` to `Print` then you'll always see an integer. The assignment of the value to `t4` turns the value back into an integer value. Alternatively, you can Print `t2 \ t1`, which will do integer division. Integer division does not turn either value into a floating-point value and will give you an integer result.

Separately you get Inf because you're doing a divide-by-zero, the `t1` variable is not shared with the `Sub`.
Reply
#4
DEFINT SHARED T Big Grin Big Grin Big Grin 

Get on it, developers!

Pete

- Sorry, channeling Clippy again.
Shoot first and shoot people who ask questions, later.
Reply
#5
Shocked 
(08-16-2024, 11:43 PM)SMcNeill Wrote: Division by 0.

T1 isn't a shared variable.

Of course!!! [Image: shocked.png]

(08-16-2024, 11:45 PM)DSMan195276 Wrote: You're seeing the difference between `/` division and `\` division. Basically, "regular" division turns both arguments into floating-point (`DOUBLE`) values before doing the division, and the result is another floating-point value. If you pass the expression directly to `Print` then you'll be printing the resulting `DOUBLE` value.

If you instead do `t4 = t2 / t1`separately and pass `t4` to `Print` then you'll always see an integer. The assignment of the value to `t4` turns the value back into an integer value. Alternatively, you can Print `t2 \ t1`, which will do integer division. Integer division does not turn either value into a floating-point value and will give you an integer result.

Separately you get Inf because you're doing a divide-by-zero, the `t1` variable is not shared with the `Sub`.

Ah, got it; thanks.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply




Users browsing this thread: 2 Guest(s)