It is currently Mon Sep 23, 2019 7:27 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 43 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Re: Sign() has to return an integer result
PostPosted: Sun Jul 14, 2019 10:02 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 13, 2010 3:45 pm
Posts: 892
mk-soft wrote:
and today you don't know how the different compilers implement them.
That's not true. There are two different paradigms and all programming languages I have tested follow one of them. This is exactly what I have contrasted here.

Only PureBasic does what it wants, doesn't have a clear line and therefore gives wrong results.

_________________
sorry for my bad english


Top
 Profile  
Reply with quote  
 Post subject: Re: Sign() has to return an integer result
PostPosted: Sun Jul 14, 2019 2:07 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3655
Location: Berlin, Germany
Hi Josh,

I understand your point in this discussion.

Anyway, this
Josh wrote:
Only PureBasic does what it wants, doesn't have a clear line and therefore gives wrong results.
is not quite correct. PureBasic does have a clear line, which is in short form:
Instead of e.g. 5/2 write 5.0/2.0

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Sign() has to return an integer result
PostPosted: Sun Jul 14, 2019 3:01 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3056
Location: Boston, MA
Round and round we go.
You cannot solve this with 5.0/2.0 when mixing variables of any type.
0.0 + 5/2 ALWAYS works. :idea:

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Sign() has to return an integer result
PostPosted: Sun Jul 14, 2019 5:04 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3655
Location: Berlin, Germany
skywalk wrote:
You cannot solve this with 5.0/2.0 when mixing variables of any type.

I have never encountered any problem with that.
Can you please provide an example of what you exactly mean?

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Sign() has to return an integer result
PostPosted: Sun Jul 14, 2019 5:15 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3056
Location: Boston, MA
From this topic, but certainly not limited to this example.

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Sign() has to return an integer result
PostPosted: Sun Jul 14, 2019 5:25 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3655
Location: Berlin, Germany
skywalk wrote:

You mean this example?
Code:
Procedure.i MySign (x.f)
  If x > 0
    ProcedureReturn 1
  ElseIf x < 0
    ProcedureReturn -1
  Else
    ProcedureReturn 0
  EndIf
EndProcedure

a.f = -3
Debug MySign(a)/100*100   ; 0

Well, that's not what I've suggested previously.

Try it this way (use 100.0 instead of 100), and see that it works correctly:
Code:
Procedure.i MySign (x.f)
  If x > 0
    ProcedureReturn 1
  ElseIf x < 0
    ProcedureReturn -1
  Else
    ProcedureReturn 0
  EndIf
EndProcedure

a.f = -3
Debug MySign(a)/100.0*100.0   ; -1.0

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Sign() has to return an integer result
PostPosted: Sun Jul 14, 2019 6:11 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3056
Location: Boston, MA
Arrrrg. Why continue to discuss effects with literal numbers 100 vs 100.0.
I'm trying to point out that math functions and macros do not always accept explicitly float parameters. Using the prefix 0.0+ ALWAYS works. It is an implied compiler directive for floating math.

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Sign() has to return an integer result
PostPosted: Sun Jul 14, 2019 6:30 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 13, 2010 3:45 pm
Posts: 892
Little John wrote:
PureBasic does have a clear line


Ok, since I can't find a clue to this clear line in the help, I try to simulate what the help should look like:

PseudoHelp wrote:
Calculation of a term in which integers and floats occur

From other programming languages you are probably used to the fact that every single calculation produces a float result if one of the both operand is a float. PureBasic does it differently, but here's what to keep in mind:

  • If an operand in the term is a float, all calculations on the right side of this float value are also performed as float calculations.
  • On the left side of this float value the same applies as described in the last point, but only a little bit. In addition, the calculations on the left side must consider the following:
    • This only applies to calculations that are connected to the float value by a * or / operator.
    • The occurrence of a + or - operator interrupts this system and what precedes it is calculated differently.
    • This system is only valid for literals. If you use a variable instead of a literal, everything can look different again.


From other programming languages, you are probably used to the fact that they produce a single boring result for a calculation. PureBasic is proud that the large and unique PB system allows to present four different results for the same calculation:
Code:
a.i = 3
Debug (5/2 + 3/3/3/3.0) ; 2.1111111111111112
Debug (5/2 + 3/3/a/3.0) ; 2.0
Debug (3/3/3/3.0 + 5/2) ; 2.6111111111111112
Debug (3/3/a/3.0 + 5/2) ; 2.5


From other programming languages you are probably used to the fact that the result of a term is always the same, no matter where the result is stored or shown. PureBasic has not made this so easy and is proud that it can deliver at least two different results here:
Code:
a.d = 2/3
#a  = 2/3
Debug a  ; 0.66666666666666663
Debug #a ; 0


From other programming languages you are probably used to being able to use comparison operations in a term and they give you a simple Boolean value. In PureBasic this is of course not so easy:

  • If you use a comparison operator in a term, you must (for whatever reason) use the Bool() operator in PB.
  • If you now believe that Bool() always returns a boolean value of 0 or 1, you are wrong. PureBasic has come up with something very special and can also supply a float value as result from Bool(). This again gives you the possibility to make the result of your term calculation absurd.


As you can see, PureBasic has really tried to make everything as complicated as possible to get wrong results. But in the forum you will find solutions to avoid some points of this.


I am sure that I haven't found all the inconsistencies offered by PB-Eval.

_________________
sorry for my bad english


Last edited by Josh on Sun Jul 14, 2019 6:36 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Sign() has to return an integer result
PostPosted: Sun Jul 14, 2019 6:35 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3655
Location: Berlin, Germany
skywalk wrote:
Arrrrg. Why continue to discuss effects with literal numbers 100 vs 100.0.

Well, I asked for an example that supports the claim that you made concerning my suggestion, but you can't provide such an example ...

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Sign() has to return an integer result
PostPosted: Sun Jul 14, 2019 6:51 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3056
Location: Boston, MA
I cannot follow your meaning?
Did you run my simple example?
Imagine it was coded and receiving variable numbers of any type.
Without 0.0+, the return is type dependent.
Very dangerous.
I'm done, this post solved a rare macro bug I had so I am grateful.

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Sign() has to return an integer result
PostPosted: Sun Jul 14, 2019 7:10 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3655
Location: Berlin, Germany
skywalk wrote:
You cannot solve this with 5.0/2.0 when mixing variables of any type.

Little John wrote:
Can you please provide an example of what you exactly mean?

Point is, that I'm still waiting for an example which substantiates your statement.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Sign() has to return an integer result
PostPosted: Sun Jul 14, 2019 9:18 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 3056
Location: Boston, MA
Code:
; Change datatypes here and see different results.
Define.b a
Define.w b
Define.a c
Define.f d
a = -3
c = 100
d = 100
Debug "-- PB    mixed type multiplication & division --"
b =       a / c * d   ; 0
Debug b
b =       a / c * d   ; 0
Debug b
Debug "-- 0.0 + mixed type multiplication & division --"
b = 0.0 + a / c * d   ; -3.0
Debug b
b = 0.0 + a / c * d   ; -3.0
Debug b

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: Sign() has to return an integer result
PostPosted: Sun Jul 14, 2019 10:20 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3655
Location: Berlin, Germany
This is a special situation, where the result of an expression which contains a division is a whole number, and thus can be meaningfully assigned to a variable that can hold only whole numbers. Anyway, the example is convincing.
Thank you!

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 43 posts ]  Go to page Previous  1, 2, 3

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye