Jump to content

Recommended Posts

  • Moderators
Posted

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:

  Reveal hidden contents

 

Posted

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!)

  Reveal hidden contents

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)

  • Moderators
Posted

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:

  Reveal hidden contents

 

Posted

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

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

 

  Reveal hidden contents

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)

Posted

@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.

  Reveal hidden contents

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)

Posted

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.

  Reveal hidden contents

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)

  • Developers
Posted (edited)
  On 7/19/2017 at 6:00 PM, 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.

Expand  

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.
  :)

Posted

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.

  Reveal hidden contents

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)

Posted

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.

Posted

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.

Posted (edited)

@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
  Reveal hidden contents

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)

Posted (edited)

I am aware of the limitations.

  On 7/20/2017 at 9:00 AM, jchd said:

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

Expand  

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
Posted
  On 7/19/2017 at 9:23 AM, 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

Expand  

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

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
  • Recently Browsing   0 members

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