Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: Controls Guy on June 28, 2021, 01:02:03 PM

Title: Type conversion for MATH results
Post by: Controls Guy 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.
Title: Re: Type conversion for MATH results
Post by: franji1 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.
Title: Re: Type conversion for MATH results
Post by: Controls Guy on June 28, 2021, 01:27:07 PM
I think you're saying it's going to do what I want, could you clarify?
Title: Re: Type conversion for MATH results
Post by: franji1 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.
Title: Re: Type conversion for MATH results
Post by: Controls Guy 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).
Title: Re: Type conversion for MATH results
Post by: franji1 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).
Title: Re: Type conversion for MATH results
Post by: Controls Guy 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.
Title: Re: Type conversion for MATH results
Post by: Controls Guy on July 03, 2021, 03:05:21 PM
Is there any speed/processor advantage to explicitly including '!=0', or to leaving it out?
Title: Re: Type conversion for MATH results
Post by: BobO 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.