Opened 15 years ago

Closed 15 years ago

# Boolean numeric conversion

Reported by: Owned by: pdaughe AutoIt 3.2.10.0 Boolean

### Description

```#CS
If you use arithmetics together with Boolean values (which is not advisable!), the following rules apply:

A Boolean true will be converted into the numeric value 1
A Boolean false will be converted into the numeric value 0

Example:
\$Boolean1 = true
\$Number1 = 100
\$Number2 = \$Boolean1 + \$Number1

This will result in \$Number2 to be the numeric value 101
#CE

\$Var = True
If \$var = 7 Then
MsgBox(4096,"", "Value is positive.")
EndIf
```

P.S. Did I submit this ticket correctly? I never used the Trac system before...I searched for existing problems and found a topic on Booleans back in 2005, but didn't see a specific example of this. My apologies if I submit this ticket incorrectly.

### comment:1 Changed 15 years ago by Valik

Uhh, no, you didn't submit the ticket correctly, you kind of got side tracked about submitting it correctly and didn't bother to tell us what the problem actually is. Everything in your post works as expected. So what's the problem?

### comment:2 follow-up: ↓ 3 Changed 15 years ago by Valik

I'm going to guess that you think True = 7 being true is wrong? The answer is simple, True is NOT demoted to an int (value 1) and compared to 7. Instead, 7 is promoted to a bool (It's non-zero so it's True when promoted) and compared to bool True which is of course true.

### comment:3 in reply to: ↑ 2 Changed 15 years ago by anonymous

I'm going to guess that you think True = 7 being true is wrong? The answer is simple, True is NOT demoted to an int (value 1) and compared to 7. Instead, 7 is promoted to a bool (It's non-zero so it's True when promoted) and compared to bool True which is of course true.

Yes, that's exactly what I thought Valik. I have several "If \$Trace Then ..." statements sprinkled throughout my code. I got tired of seeing a mouse trace and so changed it to \$Trace = 2. Of course, \$Trace is initialized either True or False.

I apologize on two fronts:

1. I read and quoted the wrong comment from the documentation. The comment I posted WOULD lead one to conclude the Boolean True would be converted to numeric 1. However, the paragraph (in the doc) right above the one I quoted explains it just as you did -- thank you.
1. I realize user posting "bugs" which aren't bugs is a headache, but this SEEMED so simple and obvious, I didn't post it first in the support forum -- I'll learn...

### comment:4 Changed 15 years ago by Valik

• Resolution set to No Bug
• Status changed from new to closed

• In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.