Bug 75332 - if variable sum=1 , the expression result "if sum = 1 then" is sometimes true and sometimes it is false
Summary: if variable sum=1 , the expression result "if sum = 1 then" is sometimes true...
Status: RESOLVED NOTOURBUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: x86-64 (AMD64) Windows (All)
: medium major
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-21 16:11 UTC by jharaquem
Modified: 2014-04-21 20:02 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
spreadsheet with macros vestocastic() and vestocastic2() (52.49 KB, application/vnd.oasis.opendocument.spreadsheet)
2014-02-21 16:11 UTC, jharaquem
Details
screenshot with example (174.01 KB, image/png)
2014-02-21 16:13 UTC, jharaquem
Details

Note You need to log in before you can comment on or make changes to this bug.
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