Sign in to follow this  
Followers 0
pdaughe

Variants

13 posts in this topic

#1 ·  Posted (edited)

Hello,

My background (longer than I like to admit :D) is with strictly-typed languages only. AutoIt is the first typeless language I've used.

Just when I was thinking I fully understand the implications (danger) of variants, coercion rules, and casting, I encounter this:

$a = 27249572530879235116

ConsoleWrite ("A = " & $a & @CRLF)

Console Output: A = 9223372036854775807

and this:

$a = 27249572530879235116

ConsoleWrite ("A = " & Number($a) & @CRLF)

(same console output)

I would have expected $A to be promoted to Int64 or a DOUBLE.

Unless I've missed it, AutoIt provides several conversion functions (Number, String, Dec, Ptr) for explicit casting, but there appears to be no functions for casting a number to a Int64 or a DOUBLE.

I know I must be misunderstanding something -- your enlightenment will be greatly appreciated.

Sincerely,

Paul

Edited by pdaughe

Share this post


Link to post
Share on other sites



$a = 27249572530879235116

ConsoleWrite ("A = " & Number($a) & @CRLF)

I would have expected $A to be promoted to Int64 or a DOUBLE.

So you're implying it was not?

What was the console output then? :D


"be smart, drink your wine"

Share this post


Link to post
Share on other sites

So you're implying it was not?

What was the console output then? :D

I'm running AutoIt 3.10 and this is what I get:

A = 9223372036854775807

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I'm running AutoIt 3.10 and this is what I get:

A = 9223372036854775807

AUtoIt limitations

Number range (integers): 64-bit signed integer

27249572530879235116 is much bigger that can be contained in a signed 64 bit integer.

The maximum is 9223372036854775807.

EDIT: minimum is -9223372036854775808

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

AUtoIt limitations

27249572530879235116 is much bigger that can be contained in a signed 64 bit integer.

The maximum is 9223372036854775807.

EDIT: minimum is -9223372036854775808

Right -- thanks for the reply Martin. BUT (and here's what I don't understand), why isn't the number cast to a DOUBLE? Isn't one of the purposes of "variants" to free the programmer from having to specifiy the variable type?

It seems "dangerous" to allow the assigment to simply take place. I realize AutoIT is not intended for financial calcuations, but it does have an impressive mathematical library.

Personally, I regard this issue as a bug, and honestly, I'm surprised, quite surprised, others don't apparently see it that way.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

It's not a bug.

If you want float, do

$a/1

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Right -- thanks for the reply Martin. BUT (and here's what I don't understand), why isn't the number cast to a DOUBLE? Isn't one of the purposes of "variants" to free the programmer from having to specifiy the variable type?

It seems "dangerous" to allow the assigment to simply take place. I realize AutoIT is not intended for financial calcuations, but it does have an impressive mathematical library.

Personally, I regard this issue as a bug, and honestly, I'm surprised, quite surprised, others don't apparently see it that way.

Don't know. Maybe you could request it as a new feature, though it can't be a very common requirement. Even a double precision float won't give the resolution to the number of digits you are expecting.

$a = 27249572530879235116.0

ConsoleWrite ("A = " & Number($a) & @CRLF)

gives

A = 2.72495725308792e+019

@Siao

$a/1

I don't think you tried that. Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Please note that none of the replies you have received so far have been from an AutoIt architect. No disrespect to those who have replied, but I know that I would try to temper how authoritative a tone I took on an issue like this.

If one of the developers does not chime in here shortly to put the issue into perspective, you may want to raise it in the bug tracker so that it receives a formal response (after searching the forum to try to be certain it has nott been addressed before).

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

I would have expected $A to be promoted to Int64 or a DOUBLE.

Unless I've missed it, AutoIt provides several conversion functions (Number, String, Dec, Ptr) for explicit casting, but there appears to be no functions for casting a number to a Int64 or a DOUBLE.

I know I must be misunderstanding something -- your enlightenment will be greatly appreciated.

Sincerely,

Paul

Since you are already familiar with typed languages... I often find myself in Autoit, doing these types of conversion, using structs.

Here's a situation that happened a while back that gave me the idea: http://www.autoitscript.com/forum/index.php?showtopic=56915

Hope it helps.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Please note that none of the replies you have received so far have been from an AutoIt architect. No disrespect to those who have replied, but I know that I would try to temper how authoritative a tone I took on an issue like this.

If one of the developers does not chime in here shortly to put the issue into perspective, you may want to raise it in the bug tracker so that it receives a formal response (after searching the forum to try to be certain it has nott been addressed before).

Dale

Thanks Dale. Actually, it's getting a little off track. I was just looking for a little help in understanding when and how AutoIt is going to promote/demote to a given data type. I"ve been using AutoIt for a over a year now and love it, primarily because it's "logical". But if a large number like that is assigned to a variable and you add one to it, you get the wrong answer. That seems "illogical". I've found variants quite easy to use and AutoIt's documentation is very good, but I misread it one time and misunderstood how and when a variable is cast to a Boolean (see Datatypes under Language Reference). My frame of reference is that a program should always perform its function correctly, regardless of what may be thrown at it. I am having difficulty in understanding just what kind of data validation is required when data is obtained externally. It's not as simple as checking string length because there could be leading character zeroes. So the intent of my question was to ask how others handle it. I'm concluding that though variants are easy, but one still has to be "aware" of data type. It's difficult to know, though, if one is on the "right track" with his thinking when you work all alone :D

Share this post


Link to post
Share on other sites

I believe Valik already shot down a request for this, I can't find it though.

Share this post


Link to post
Share on other sites

Since you are already familiar with typed languages... I often find myself in Autoit, doing these types of conversion, using structs.

Here's a situation that happened a while back that gave me the idea: http://www.autoitscript.com/forum/index.php?showtopic=56915

Hope it helps.

Thanks SmOke_N -- I've benefitted from several of your posts (thanks), but this one....well, my wife says I'm sugar sweet and razor sharp, but I'm going to have to study that one for a while! I am "comfortable" with DLLStructs, but that one makes me scratch my head! (he, he)

Share this post


Link to post
Share on other sites

Thanks SmOke_N -- I've benefitted from several of your posts (thanks), but this one....well, my wife says I'm sugar sweet and razor sharp, but I'm going to have to study that one for a while! I am "comfortable" with DLLStructs, but that one makes me scratch my head! (he, he)

It was only to give you a generalization on how to use math with int64/float whatever.

PaulIA did a Int to Float udf a while back: http://www.autoitscript.com/forum/index.ph...st&p=349084

Maybe that will make more sense on the transformation, but for the math, you'll have to look at the examples I wrote a bit closer like you said.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
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
Sign in to follow this  
Followers 0