# PureBasic Forum

 It is currently Thu May 28, 2020 6:16 am

 All times are UTC + 1 hour

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: The "100 < 1.1*1" problemPosted: Wed Feb 20, 2019 6:31 pm
 User

Joined: Fri Jun 21, 2013 11:59 am
Posts: 14
Code:
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

Top

 Post subject: Re: The "100 < 1.1*1" problemPosted: Wed Feb 20, 2019 7:11 pm

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3266
Location: Boston, MA
Not gonna lie, this is a pain in the A\$\$!
However, it is rare, that the inequality is formed without variables...
Code:
Global.L x = 100
Global.d y = 1.0
Global.d z = 1.1
If x < (y)
EndIf
If x < (z)
EndIf
If x < (1.0)
EndIf
If x < (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

Top

 Post subject: Re: The "100 < 1.1*1" problemPosted: Wed Feb 20, 2019 10:01 pm

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1907
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.

Top

 Post subject: Re: The "100 < 1.1*1" problemPosted: Wed Feb 20, 2019 10:28 pm
 Enthusiast

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 518
Location: Germany, Saarbrücken
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:
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:
Global.L x = 100
If Abs(x) < 1.1 * 1
Debug "BAD!  100 < 1.1 * 1"
EndIf

All together:
Code:
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.

Top

 Post subject: Re: The "100 < 1.1*1" problemPosted: Tue May 14, 2019 12:58 pm

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 3698
Location: Italy

Reported it here -> viewtopic.php?f=4&t=72339&p=533241#p533241

_________________

Top

 Post subject: Re: The "100 < 1.1*1" problemPosted: Tue May 14, 2019 4:09 pm

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 2544
Would be fine if Fred could provide some simple casting functions...

Code:
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

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 6 posts ]

 All times are UTC + 1 hour

#### Who is online

Users browsing this forum: No registered users and 6 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - IDE    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite