Modify

Opened 10 years ago

Closed 10 years ago

#3235 closed Bug (No Bug)

Floor isn't accurate

Reported by: TommyDDR Owned by:
Milestone: Component: AutoIt
Version: 3.3.14.0 Severity: None
Keywords: Cc:

Description

I recently need to count the numbers of digits in a number, so i do my stuff with Log10 and i found a problem :

Local $log10_1000 = Log(1000)/Log(10)        ; Log(1000)/Log(10) = Log10(1000) = 3
Local $floor_log10_1000 = Floor($log10_1000) ; Floor(3) = 3
Local $int3 = Int(3)                         ; Int(3) = 3
Local $floor_int3 = Floor($int3)             ; Floor(3) = 3
ConsoleWrite($log10_1000 & @CRLF)            ; Display 3
ConsoleWrite($floor_log10_1000 & @CRLF)      ; Display 2 ??
ConsoleWrite($int3 & @CRLF)                  ; Display 3
ConsoleWrite($floor_int3 & @CRLF)            ; Display 3

Floor(Log(1000)/Log(10)) display 2 instead of 3.

Attachments (0)

Change History (1)

comment:1 by Melba23, 10 years ago

Resolution: No Bug
Status: newclosed

Dividing in AutoIt automatically results in a Double (floating point) return value. In this case $log10_1000 does not hold the exact value 3 as you can see by running this line at the end of your script:

ConsoleWrite(Hex($log10_1000) & " - " & Hex($int3) & @CRLF)

which returns

4007FFFFFFFFFFFF - 00000003

So as the $log10_1000 variable actually holds a value slightly less than 3, Floor correctly returns 2. No bug.

Could I suggest opening a forum thread when you next come across a floating point "error" like this - they are rarely bugs.

M23

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.