Bug 75332

Summary: if variable sum=1 , the expression result "if sum = 1 then" is sometimes true and sometimes it is false
Product: LibreOffice Reporter: jharaquem
Component: BASICAssignee: Not Assigned <libreoffice-bugs>
Status: RESOLVED NOTOURBUG QA Contact:
Severity: major    
Priority: medium CC: jbfaure
Version: unspecified   
Hardware: x86-64 (AMD64)   
OS: Windows (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: spreadsheet with macros vestocastic() and vestocastic2()
screenshot with example

Description jharaquem 2014-02-21 16:11:57 UTC
Created attachment 94527 [details]
spreadsheet with macros vestocastic() and  vestocastic2()

tested from libreoffice 3.6 in windows x32/64 and ubuntu x32/64

Function vEstocastic (vector()) as boolean
dim i, m as integer
dim suma as variant
	suma = 0
	m = ubound(vector, 2)
	for i = 1 to m
		suma = suma + vector(1, i)
	next
	if suma = 1 then               'if the variable suma = 1
		vEstocastic = true     'somtimes is true
	else                           'and
		vEstocastic = false    'sometimes is false
	end if
End Function

and.....


Function eNumeric (elemento) as boolean
	if isnumeric(elemento) then      'if elemento = .0.3
		eNumeric = true          'the result is incorrectly true
	else
		eNumeric = false         '
	end if
End Function
Comment 1 jharaquem 2014-02-21 16:13:29 UTC
Created attachment 94528 [details]
screenshot with example
Comment 2 m.a.riosv 2014-02-22 00:27:20 UTC
Hi jharaquem, thanks for reporting.

Maybe it is related to http://en.wikipedia.org/wiki/Floating_point#IEEE_754:_floating_point_in_modern_computers

Please try rounding suma equation, perhaps can help.
Comment 3 jharaquem 2014-02-22 02:41:07 UTC
I do not think that is related, i've also tried to change the type of variables and nothing


I tried with the values ​​{ 0.7 0.2 0.1 0 } whose sum is 1.0 in different order, and does not work.

and ".0.3" not is numeric, in the case of vnumeric function

please verify the attachments and try macros

this is my first report
sorry for my english

:)
Comment 4 m.a.riosv 2014-02-22 03:28:21 UTC
Sorry I can't help with macros.
Comment 5 Jean-Baptiste Faure 2014-04-21 20:02:43 UTC
basic rule in computational programming: it is always a bad idea to compare a floating number to an integer for equality.

Please ask for help on macro on askLibo or on the users mailing list.

Closing as NotOurBug.

Best regards. JBF

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.