The "100 < 1.1*1" problem

Everything else that doesn't fall into one of the other PB categories.
AtomUpgrader
User
User
Posts: 15
Joined: Fri Jun 21, 2013 11:59 am

The "100 < 1.1*1" problem

Post by AtomUpgrader »

Code: Select all

Global.L x
x = 100
If x < 1.0*1
    Debug "100 < 1.0*1"
Endif
If x < 1.1*1
    Debug "100 < 1.1*1"
Endif
Please give out your results!
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: The "100 < 1.1*1" problem

Post by skywalk »

Not gonna lie, this is a pain in the A$$! :evil:
However, it is rare, that the inequality is formed without variables... :wink:

Code: Select all

Global.L x = 100
Global.d y = 1.0
Global.d z = 1.1
If x < (y)
  Debug "BAD!  100 < y"
EndIf
If x < (z)
  Debug "BAD!  100 < z"
EndIf
If x < (1.0)
  Debug "BAD!  100 < 1.0"
EndIf
If x < (1.1)
  Debug "BAD!  100 < 1.1"
EndIf
If x < (1.0 * 1)
  Debug "BAD!  100 < 1.0 * 1"
EndIf
If x < (1.1 * 1)
  Debug "BAD!  100 < 1.1 * 1"
EndIf
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: The "100 < 1.1*1" problem

Post by Dude »

I get "100 < 1.1*1" outputted with the code as it stands.

But I get no outputs at all if I use "Global.f x" which is how it's meant to be. If you're going to use float calculations ("1.1*1") then the variable holding the result must also be of float type (not long type). Make "x" a float and you'll see that it works.
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: The "100 < 1.1*1" problem

Post by NicTheQuick »

Looks for me like a bug. Purebasic has to handle type conversions properly without explicit casting. If you write the following it works properly.

Code: Select all

Global.L x = 100
If x < Int(1.1 * 1)
  Debug "BAD!  100 < 1.1 * 1"
EndIf
There other way around it also works

Code: Select all

Global.L x = 100
If Abs(x) < 1.1 * 1
  Debug "BAD!  100 < 1.1 * 1"
EndIf
All together:

Code: Select all

Global.i x = 100

If x < 1.1 * 1
  Debug "BAD!  100 < 1.1 * 1"
EndIf

If x < Int(1.1 * 1)
	Debug "BAD!  100 < Int(1.1 * 1)"
EndIf

If Abs(x) < 1.1 * 1
	Debug "BAD!  Abs(100) < 1.1 * 1"
EndIf
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: The "100 < 1.1*1" problem

Post by luis »

@AtomUpgrader

Reported it here -> viewtopic.php?f=4&t=72339&p=533241#p533241
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Michael Vogel
Addict
Addict
Posts: 2666
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: The "100 < 1.1*1" problem

Post by Michael Vogel »

Would be fine if Fred could provide some simple casting functions...

Code: Select all

Macro Integer(value)
	Int((value))
EndMacro
Macro Float(value)
	1.0*(value)	
EndMacro

Global.i x
x = 100
If x < 1.0*1
	Debug "100 < 1.0*1"
EndIf
If x < 1.1*1
	Debug "100 < 1.1*1"
EndIf
If x < Integer(1.1*1)
	Debug "100 < 1.1*1"
EndIf
If Float(x) < 1.1*1
	Debug "100 < 1.1*1"
EndIf
Post Reply