Different results comparing "1.0 <= 1.0" on different system

Just starting out? Need help? Post your questions and find answers here.
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Different results comparing "1.0 <= 1.0" on different system

Post by Lebostein »

Hi,

I have extracted and reduced the following code from my project to solve the problem. In this special case I compare 1.0 with 1.0 but the results are different:

On Windows XP 32-Bit I get:
1.0
1.0
1.0
1
1
On Mac OS 64-Bit I get:
1.0
1.0
1.0
0
1

Code: Select all

Structure file
  m_width.i
  m_heigh.i
EndStructure

Structure term
  min.i
  max.i
EndStructure

Procedure Inside(value.d, *term.term, faktor.d = 1)
  Debug value
  Debug *term\min * faktor
  Debug *term\max * faktor
  Debug Bool(value >= *term\min * faktor)
  Debug Bool(value <= *term\max * faktor)
EndProcedure

Procedure.d GetRatio(*file.file): Protected result.d
  If *file\m_width > 0 And *file\m_heigh > 0: result = *file\m_width / *file\m_heigh: EndIf
  ProcedureReturn result
EndProcedure

Define datei.file
datei\m_heigh = 480
datei\m_width = 480
Define grenze.term
grenze\min = 1000
grenze\max = 1000

Inside(GetRatio(datei), grenze, 0.001)
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Different results comparing "1.0 <= 1.0" on different sy

Post by Lebostein »

I have reduced the problem to

Code: Select all

factor.d = 0.001
Debug 1000 * factor ; = 1.0
Debug Bool(1.0 >= 1000 * factor) ; = 0 ???
Debug Bool(1.0 <= 1000 * factor) ; = 1
check.d = 1000 * factor
Debug Bool(1.0 >= check) ; = 1
Debug Bool(1.0 <= check) ; = 1
:?:

Other courious thing: Bool() returns a float?

Code: Select all

Debug Bool(1.0 >= 1000 * 0.001) ; = 1.0
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Different results comparing "1.0 <= 1.0" on different sy

Post by skywalk »

I do not get your error on v561 on x64.
But I do see Bool(float) returns a float?

Code: Select all

Debug Bool(#PI)   ; 3.1415926535897931
Debug Bool(0.001) ; 0.001
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Different results comparing "1.0 <= 1.0" on different sy

Post by Little John »

skywalk wrote:But I do see Bool(float) returns a float?

Code: Select all

Debug Bool(#PI)   ; 3.1415926535897931
Debug Bool(0.001) ; 0.001
[u]Manual[/u] wrote:If the boolean expression is true, it will return #True, otherwise it will return #False.

Code: Select all

Debug Bool(4*0.5 + 3)  ; shows 5.0
:D

I think the point is, that neither "#PI" nor "0.001" nor "4*0.5 + 3" are boolean expressions.
However, according to the principle of least surprise, it would make sense if Bool() would always return either #True or #False.

IMHO, it would be consistent if

Code: Select all

Debug Bool(#PI)
would yield the same result as

Code: Select all

Debug Bool(#PI <> 0)
And this should be #True (1) or #False (0), and not a floating point value.
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Different results comparing "1.0 <= 1.0" on different sy

Post by Lebostein »

Is this a bug or not?
Little John
Addict
Addict
Posts: 4519
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Different results comparing "1.0 <= 1.0" on different sy

Post by Little John »

Lebostein wrote:I have reduced the problem to

Code: Select all

factor.d = 0.001
Debug 1000 * factor ; = 1.0
Debug Bool(1.0 >= 1000 * factor) ; = 0 ???
Debug Bool(1.0 <= 1000 * factor) ; = 1
check.d = 1000 * factor
Debug Bool(1.0 >= check) ; = 1
Debug Bool(1.0 <= check) ; = 1
:?:
I can reproduce the issue with PB 5.45 LTS (x86) on Linux Mint 18.2 Cinnamon.
No problem though with PB 5.61 (x64) on Windows 10.
Lebostein wrote:Is this a bug or not?
To me it looks like a bug.
Post Reply