pdaughe Posted April 25, 2008 Share Posted April 25, 2008 (edited) Hello, My background (longer than I like to admit ) 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 April 26, 2008 by pdaughe Link to comment Share on other sites More sharing options...
Siao Posted April 25, 2008 Share Posted April 25, 2008 $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? "be smart, drink your wine" Link to comment Share on other sites More sharing options...
pdaughe Posted April 26, 2008 Author Share Posted April 26, 2008 So you're implying it was not?What was the console output then? I'm running AutoIt 3.10 and this is what I get:A = 9223372036854775807 Link to comment Share on other sites More sharing options...
martin Posted April 26, 2008 Share Posted April 26, 2008 (edited) I'm running AutoIt 3.10 and this is what I get:A = 9223372036854775807AUtoIt limitationsNumber range (integers): 64-bit signed integer27249572530879235116 is much bigger that can be contained in a signed 64 bit integer. The maximum is 9223372036854775807.EDIT: minimum is -9223372036854775808 Edited April 26, 2008 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. Link to comment Share on other sites More sharing options...
pdaughe Posted April 28, 2008 Author Share Posted April 28, 2008 AUtoIt limitations27249572530879235116 is much bigger that can be contained in a signed 64 bit integer. The maximum is 9223372036854775807.EDIT: minimum is -9223372036854775808Right -- 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. Link to comment Share on other sites More sharing options...
Siao Posted April 28, 2008 Share Posted April 28, 2008 (edited) It's not a bug. If you want float, do $a/1 Edited April 28, 2008 by Siao "be smart, drink your wine" Link to comment Share on other sites More sharing options...
martin Posted April 28, 2008 Share Posted April 28, 2008 (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/1I don't think you tried that. Edited April 28, 2008 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. Link to comment Share on other sites More sharing options...
DaleHohm Posted April 28, 2008 Share Posted April 28, 2008 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 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 28, 2008 Moderators Share Posted April 28, 2008 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,PaulSince 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=56915Hope 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. Link to comment Share on other sites More sharing options...
pdaughe Posted April 28, 2008 Author Share Posted April 28, 2008 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).DaleThanks 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 Link to comment Share on other sites More sharing options...
weaponx Posted April 28, 2008 Share Posted April 28, 2008 I believe Valik already shot down a request for this, I can't find it though. Link to comment Share on other sites More sharing options...
pdaughe Posted April 28, 2008 Author Share Posted April 28, 2008 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=56915Hope 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) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 28, 2008 Moderators Share Posted April 28, 2008 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=349084Maybe 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now