News:

  • June 07, 2026, 11:08:17 PM

Login with username, password and session length

Author Topic: Type conversion for MATH results  (Read 11267 times)

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Type conversion for MATH results
« on: June 28, 2021, 01:02:03 PM »
I want to check the presence of a certain bit in a DWORD.    I'm doing

Code: [Select]
MATH V619:0 "MyDword[idx] & BitMask"
...where BitMask is a DWORD with one bit in the position of interest.  I've often done that with an inequality (Stuff != 0), but I'm assuming that if I want to evaluate an expression as a boolean, the result will be true if non-zero and false for zero.   Is that right, or must I do an inequality in the expression string?   Couldn't find in MATH help where it addressed that.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Type conversion for MATH results
« Reply #1 on: June 28, 2021, 01:22:11 PM »
I want to check the presence of a certain bit in a DWORD.    I'm doing

Code: [Select]
MATH V619:0 "MyDword[idx] & BitMask"
...where BitMask is a DWORD with one bit in the position of interest.  I've often done that with an inequality (Stuff != 0), but I'm assuming that if I want to evaluate an expression as a boolean, the result will be true if non-zero and false for zero.   Is that right, or must I do an inequality in the expression string?   Couldn't find in MATH help where it addressed that.

Sorry, since you are going to a BIT, it will evaulate 0 or non-zero as assigning 0 or 1.
« Last Edit: June 28, 2021, 01:23:51 PM by franji1 »

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: Type conversion for MATH results
« Reply #2 on: June 28, 2021, 01:27:07 PM »
I think you're saying it's going to do what I want, could you clarify?
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Type conversion for MATH results
« Reply #3 on: June 28, 2021, 01:32:50 PM »
I think you're saying it's going to do what I want, could you clarify?

Sorry about that - yes it will do as you want.  When assigning a 32 bit integer or real to a bit, it evaluates zero/non-zero as 0/1.

Sorry for the confusion.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: Type conversion for MATH results
« Reply #4 on: June 28, 2021, 01:38:41 PM »
Perfect, thanks!    That's what I expected but some preliminary results made me think it might not be evaluating that way.

You might want to add to the help how MATH handles differences between expression and result types.   For example, let's say the expression is boolean and the result is a number.   I assume it will do the same and assign 1 or 0 for TRUE or FALSE?  (can't conjure up a use case for that one, but that probably means I haven't run across it yet).
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Type conversion for MATH results
« Reply #5 on: June 28, 2021, 02:01:03 PM »
fyi, this behavior is in multiple instructions.  Any kind of value-based assignment (e.g. MOVE, MOVER, MATH, COPY, etc.) where the DESTINATION is a BIT, evaluates the FINAL SOURCE integer/real value of zero/non-zero and assigns 0/1, respectively.

There is no value TRUE or FALSE (but you could make 2 symbolic constants).

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: Type conversion for MATH results
« Reply #6 on: June 28, 2021, 02:05:21 PM »
fyi, this behavior is in multiple instructions.  Any kind of value-based assignment (e.g. MOVE, MOVER, MATH, COPY, etc.) where the DESTINATION is a BIT, evaluates the FINAL SOURCE integer/real value of zero/non-zero and assigns 0/1, respectively.

There is no value TRUE or FALSE (but you could make 2 symbolic constants).

Noted.    As far as TRUE and FALSE, I was using those for clarity in describing boolean/bit ON and OFF (or 1 and 0).   I know there's no predefined values with those names.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3607
  • Darth Ladder
Re: Type conversion for MATH results
« Reply #7 on: July 03, 2021, 03:05:21 PM »
Is there any speed/processor advantage to explicitly including '!=0', or to leaving it out?
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6158
  • Yes Pinky, Do-more will control the world!
Re: Type conversion for MATH results
« Reply #8 on: July 03, 2021, 08:06:24 PM »
Is there any speed/processor advantage to explicitly including '!=0', or to leaving it out?

Negligible, but less is faster.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO