Modify

Opened 17 years ago

Closed 17 years ago

#146 closed Bug (No Bug)

Boolean numeric conversion

Reported by: pdaughe Owned by:
Milestone: Component: AutoIt
Version: 3.2.10.0 Severity:
Keywords: Boolean Cc:

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.

Attachments (0)

Change History (4)

comment:1 Changed 17 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: Changed 17 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 17 years ago by anonymous

Replying to 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.

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 17 years ago by Valik

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

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

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

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.