rbhkamal Posted April 3, 2009 Share Posted April 3, 2009 (edited) Why negative values evaluate as true in the following: if -1 then ;kill self endif Was this always the case? Or did the behavior change at some point? Edited April 3, 2009 by rbhkamal "When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix Link to comment Share on other sites More sharing options...
YellowLab Posted April 3, 2009 Share Posted April 3, 2009 I don't know if this has always been the case, but I would assume yes. Usually, only 0=FALSE all other values = true. Bob You can't see a rainbow without first experiencing the rain. Link to comment Share on other sites More sharing options...
GEOSoft Posted April 3, 2009 Share Posted April 3, 2009 Why negative values evaluate as true in the following: if -1 then ;kill self endif Was this always the case? Or did the behavior change at some point?It returns True because it is True $iVal = -1 If $iVal = -1 Then MsgBox(0, "Results", "It's True") Else MsgBox(0, "Results", "It's False") EndIf George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
rbhkamal Posted April 3, 2009 Author Share Posted April 3, 2009 I understand that AutoIt treats -1 as true... I discovered it the hard way. But it doesn't make sense; negative values are almost always an error in all languages. What is the logic behind this behavior? "When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix Link to comment Share on other sites More sharing options...
trancexx Posted April 3, 2009 Share Posted April 3, 2009 I understand that AutoIt treats -1 as true... I discovered it the hard way. But it doesn't make sense; negative values are almost always an error in all languages. What is the logic behind this behavior?Logic is this:-1 is not nothing ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Developers Jos Posted April 3, 2009 Developers Share Posted April 3, 2009 I understand that AutoIt treats -1 as true... I discovered it the hard way. But it doesn't make sense; negative values are almost always an error in all languages. What is the logic behind this behavior?You have 2 options being True or False. 0 = False, anything else is True.Doesn't that make sense?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 More sharing options...
GEOSoft Posted April 3, 2009 Share Posted April 3, 2009 I understand that AutoIt treats -1 as true... I discovered it the hard way. But it doesn't make sense; negative values are almost always an error in all languages. What is the logic behind this behavior?-1 does equal -1 therefore it is true. What can be simpler than that? As has been stated Only 0 or an empty string ("") are false when looking at the value of variables. I think what you want would be a new function like Boolean() where only positive values resolve to True George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
rbhkamal Posted April 3, 2009 Author Share Posted April 3, 2009 (edited) Logic is this: -1 is not nothing I see... thanks [Edit] Thanks everyone... Edited April 3, 2009 by rbhkamal "When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix Link to comment Share on other sites More sharing options...
GEOSoft Posted April 3, 2009 Share Posted April 3, 2009 Actually if you want another test then try this one and see the difference. $iVal = -1 If NOT $iVal Then MsgBox(0, "Results", "It's False") Else MsgBox(0, "Results", "It's True") EndIf That's why the keyword NOT is there George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
rbhkamal Posted April 4, 2009 Author Share Posted April 4, 2009 Actually if you want another test then try this one and see the difference. $iVal = -1 If NOT $iVal Then MsgBox(0, "Results", "It's False") Else MsgBox(0, "Results", "It's True") EndIf That's why the keyword NOT is there Thanks "When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix Link to comment Share on other sites More sharing options...
Ascend4nt Posted April 4, 2009 Share Posted April 4, 2009 A value of 'True' typically represents -1 or 1 in a language. -1 is the same as all bits set.Here's what MSDN says:The encoding for logical FALSE is all bits set to zero (0x0), and the encoding for logical TRUE is all bits set to 1 or 0xFFFFhttp://msdn.microsoft.com/en-us/library/cc...0(PROT.10).aspx My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 4, 2009 Share Posted April 4, 2009 True and false are relative. The easiest difference is false equals zero and true equals non zero. That's how most processors run anyways. There are checks for things like "if the value in some register or on the top of the stack equals zero, branch {here}." Link to comment Share on other sites More sharing options...
Ascend4nt Posted April 4, 2009 Share Posted April 4, 2009 I'm not sure how other processors work, but for the Intel chipsets, there are no built-in 'bool' types/operations or 'If variable' logic tests, unless you count the 'cx' register and its 'jcxz' instruction - but that itself requires the register to first contain the data you'd like to test. (which in the case of most variables requires a 'mov' to cx first). There are conditional jumps\operations based on a 'zf' (zero-flag), but these must be preceded by a compare or 'test' operation. To emulate 'If' tests in higher-level languages, you would either use 'test' to test if certain/all bits are set, or compare a value to zero (which logically is the same as 'If x=0' or 'If x<>0'). Also, using 'not' would be the equivalent of changing a value's status from true to false (no-bits set to all-bits set and vice versa). So basically, no - the processor doesn't run the same way as 'If variable' logic statements work. That is something you will only find in higher-level languages, which themselves can use any set of machine instructions they like, though the easiest would be 'cmp [var],0'. My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 4, 2009 Share Posted April 4, 2009 Who was that comment directed at? 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