Issue 107277 - basic: adding currency values overflows when result > (2^31)/10000
Summary: basic: adding currency values overflows when result > (2^31)/10000
Status: ACCEPTED
Alias: None
Product: General
Classification: Code
Component: scripting (show other issues)
Version: OOo 3.1
Hardware: All Windows XP
: P3 Trivial (vote)
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-27 19:38 UTC by jsatrus
Modified: 2017-05-20 10:47 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description jsatrus 2009-11-27 19:38:06 UTC
Try the code below. When you add 2 Currency values and the result is bigger than
(2^31)/10000 the number you get is not expected, is like an overflow.
It does not matter if the numbers you are adding are smaller or bigger than
(2^31)/10000  (like problems because the result needs more than 4 bytes)
(3 different patterns to choose in the code by removing REMs)

I guess this bug should also happen in other OSs

REM  *****  BASIC  *****
REM P0WER(2;31) = 2.147.483.648      (using the "." as thousand separator)
REM POWER(2;31)/10000 = 214.748,3648

Const inc As Currency = 1
Const basenumber As Currency = 214745
Const topnumber As Currency = 214750

REM	Const inc As Currency = 2000
REM	Const basenumber As Currency = 300000
REM	Const topnumber As Currency = 310000

REM	Const inc As Currency = 300000
REM	Const basenumber As Currency = 300000
REM	Const topnumber As Currency = 1000000

Sub Main
	Dim NewTotalPrice As Currency
	Dim OldTotalPrice As Currency
	
	OldTotalPrice = basenumber
	Do	While OldTotalPrice < topnumber
		NewTotalPrice = OldTotalPrice + inc
		MsgBox "Adding " & inc & " to " + OldTotalPrice + " results " & NewTotalPrice
		OldTotalPrice = NewTotalPrice
	Loop

End Sub
Comment 1 bmarcelly 2009-11-29 09:01:36 UTC
It is uglier than you think. Try this :

Dim a As Currency
a = 300000
MsgBox( a )
a = a + 0.0000
MsgBox( a ) ' My PC displays : 75632326542153.2672

Don't use Currency, it is completely bugged.
See Issue 31001
See Issue 54049
See Issue 91121
Comment 2 kay.ramme 2009-11-30 09:56:51 UTC
Andrease, please have a look.
Comment 3 ab 2009-12-18 08:32:40 UTC
STARTED, 3.x
Comment 4 Marcus 2017-05-20 10:47:55 UTC
Reset assigne to the default "issues@openoffice.apache.org".