Jump to content

Operators


Recommended Posts

  • Moderators

breakbadsp,

Welcome to the AutoIt forums.

AutoIt can often produce strange results when comparing dissimilar datatypes. In this case I would suggest that AutoIt is forcing both sides to numbers - and so "123a" becomes 123, which is obviously the same as the number to which it is being compared. Here is an example of what is happening:

ConsoleWrite( Number("123a") & @CRLF)

The trick is to get both sides of any comparison into the same datatype so that AutoIt does not have to make any assumptions about which type to use.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

The RHS value 123 is numeric, hence a numeric comparison is made, forcing conversion of "123a" using Number().

Your condition is then equivalent to (Number("123a") = 123) and is trivially True.

(As Melba just said, fast Melba!)

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • Moderators

Trong,

The "==" operator does indeed force both sides to strings before making a case-sensitive comparison, but I still believe that it is best if the user explicitly defines the datatype to use so that there can be no doubt as to what exactly is being compared.

An example which often causes problems is getting a value from an ini file (always returned as a string) which must be compared to a numeric value within the script - if the user is not careful the result will not be as expected.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

These values aren't meaningful as they by far exceed max int64:

ConsoleWrite(VarGetType(999999999999999999999) & ' -> ' & 999999999999999999999 & @LF)

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • Developers
9 minutes ago, Trong said:

with = compare! use string type is better

This is not a correct statement and should be totally ignored! 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

@Jos,

Is it possible that Au3Check would cry wolf when it encouters such invalid integers (int64 speaking)? It would certainly be painfully slow to check every integral operation at runtime, but at check/compile time we could afford wasting a number of cycles to do that.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Exactly, so it's the programmer responsability to sanity-check user input so as to carefully avoid undefined/unexpected behavior!

How would you otherwise add 43 to 999999999999999999999? That would need BigInt UDF, wich isn't exactly the same code as regular (in-range) integers.

The first rule of programming is "know your data". Said otherwise, sanitize and validate input of doubtful validity.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • Developers
1 hour ago, jchd said:

@Jos,

Is it possible that Au3Check would cry wolf when it encouters such invalid integers (int64 speaking)? It would certainly be painfully slow to check every integral operation at runtime, but at check/compile time we could afford wasting a number of cycles to do that.

That should be possible. I will make it an Error.

Jos   

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Works like a charm, warm thanks. Sorry to have put you in business (again) for that but the occasion was good enough to deserve fixing, at the check step at least.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

These numbers are simply overflowing and the interpreter is treating them as integers. The question is: if the interpreter thinks it's alright, then why would AU3Check throw an error? I personally think they should be converted to floats by the interpreter, but I wouldn't know how to do that. This is the reason for Operator64 - which tries to remain accurate with all numeric ranges and datatypes.

Link to comment
Share on other sites

  • Developers

I can make that a warning too by au3check in case that's more appropriate, but won't be opening the autoit3 source to make changes.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I'm not sure what's best and would be happy either way. I do think a warning is appropriate. If the interpreter were to reject these values, then there would be every reason to report an error. As things are, it's a bit unclear if this behaviour really is by design. If not then it ought to be a bug.

Link to comment
Share on other sites

@czardas,

Converting out of range integers into floats isn't doable, as it opens a whole new big can of worms. For instance what would the following code do?

Local $MyBigInt = 999999999999999999900
ConsoleWrite($MyBigInt & @LF)
$MyBigInt += 90
ConsoleWrite($MyBigInt & @LF & @LF)
For $i = $MyBigInt To $MyBigInt + 9
    ConsoleWrite($i & @LF)
Next

I've canned distinct issues here and none can be solved by floats. Have fun making the initial value a float by appending .0

Similar issues can arise in otherwise legal and inconspiciously wrong code:

Local $MyBigInt = 9223372036854775000    ; this initial value can come from Jove or user or ...
ConsoleWrite($MyBigInt & @LF)
$MyBigInt += 8
ConsoleWrite($MyBigInt & @LF & @LF)
For $i = 1 To 9
    ConsoleWrite($MyBigInt + 100 * $i & @LF)
Next

Very few languages offer guards against integral under- overflow and the only serious way out is to support arbitrary-size integer arithmetic out of the box. That or flag invalid constants at check time and warn the programmers that integers must fit in a signed int64.

Edited by jchd
spelling

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

I am aware of the limitations.

32 minutes ago, jchd said:

Have fun making the initial value a float by appending .0

I can and I do (edit : although not by appending .0)! :)

MsgBox(0, "", 1.0e+099 + 90)

No significant issues here!

Edit: Converting hard coded large integers won't work without the use of strings though. I just try to avoid overflow on calculations - only making conversions when needed. Some kind of warning is a good idea in any event.

Edited by czardas
Link to comment
Share on other sites

On 7/19/2017 at 2:53 PM, Melba23 said:

breakbadsp,

Welcome to the AutoIt forums.

AutoIt can often produce strange results when comparing dissimilar datatypes. In this case I would suggest that AutoIt is forcing both sides to numbers - and so "123a" becomes 123, which is obviously the same as the number to which it is being compared. Here is an example of what is happening:

ConsoleWrite( Number("123a") & @CRLF)

The trick is to get both sides of any comparison into the same datatype so that AutoIt does not have to make any assumptions about which type to use.

M23

Got it , Its just the implementation. Anyways using == is the best option if you want to avoid the extra typecasting headache

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...