Jump to content

2 ^ 62 = 4611686018427387905 ???


Recommended Posts

$iInt64 = Int(2 ^ 62, 2)
ConsoleWrite($iInt64 & @lf)

= 4611686018427387905 :)

Bug starts at 2 ^ 49 and further.

2 ^ 63 gives -9223372036854775808 as result. Why negative?

AutoIt 3.3.14.5.

PS:

I also found other math bug(s) in more complex code but can not determine where. Maybe it is related.

Edited by timsky
Link to comment
Share on other sites

16 minutes ago, timsky said:

2 ^ 63 gives -9223372036854775808 as result. Why negative?

Leftmost bit = 1 thus negative ?  But you got definitively a bug here. You should report it in bug tracker.

Try :

MsgBox ($MB_SYSTEMMODAL,"",Hex (2^48))
MsgBox ($MB_SYSTEMMODAL,"",Hex (2^49))

Obvious. 

Link to comment
Share on other sites

From the help file for Int()

Quote

This function makes minor corrections to floating point numbers to account for the imprecise nature of floating point numbers. For example, the floating point expression 0.7 + 0.2 + 0.1 produces a floating point number that is not quite 1.0. Int() corrects for this anomaly, however, certain extremely rare circumstances may lead to Int() returning an unexpected value (the odds of getting an unexpected value are less than if Int() did not attempt any correction at all).

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

How about an iPow function?

 

ConsoleWrite(iPow(2, 49) & @CRLF)
ConsoleWrite(iPow(2, 50) & @CRLF)
ConsoleWrite(iPow(2, 62) & @CRLF)
ConsoleWrite(iPow(2, 63) & @CRLF)

Func iPow($iBase, $iExp, $sType = "UINT64")
    $tRes = DllStructCreate($sType)
    DllStructSetData($tRes, 1, 1)

    While $iExp > 0
        If BitAND($iExp, 1) = 1 Then
            DllStructSetData($tRes, 1, DllStructGetData($tRes, 1) * $iBase)
        EndIf
        $iExp = BitShift($iExp, 1) ;Right shift 1
        $iBase *= $iBase
    WEnd
    Return DllStructGetData($tRes, 1)
EndFunc   ;==>iPow
562949953421312
1125899906842624
4611686018427387904
-9223372036854775808

note the 2 ^ 63 still outputs a negative number but that is a limitation of Autoit not the algorithm and further processing would be needed

Link to comment
Share on other sites

17 minutes ago, Bilgus said:

but that is a limitation of Autoit

That is a limitation of working with floating point numbers in any system.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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