Page 1 of 2
What? Bool() problem..
Posted: Fri Feb 22, 2013 9:57 pm
by utopiomania
Code: Select all
N(1) = N(1) + (Yr % 4 = 0) | (Yr % 100 = 0) | (Yr % 400 = 0)
X Line 8: Boolean comparisons can only be used with test operators
like If, While, Repeat. Use Bool() instead.
?? Worked in the past..

Re: What? Bool() problem..
Posted: Fri Feb 22, 2013 10:56 pm
by STARGÅTE
Code: Select all
N(1) = N(1) + Bool(Yr % 4 = 0) | Bool(Yr % 100 = 0) | Bool(Yr % 400 = 0)
Re: What? Bool() problem..
Posted: Sun Feb 24, 2013 1:14 am
by utopiomania
Ok, thanks...

Re: What? Bool() problem..
Posted: Sun Feb 24, 2013 6:08 am
by Little John
It looks as if this piece of code should calculate a leap day -- but it does
not do so correctly.
For calculating a leap day, use e.g. the following code
Code: Select all
N(1) + Bool((year % 4 = 0 And year % 100 <> 0) Or year % 400 = 0)
In order to see the different results of both code snippets, try e.g. for
year = 1900.
Re: What? Bool() problem..
Posted: Sun Feb 24, 2013 10:04 pm
by utopiomania
The code calculated leap years correctly until newer versions of PB stopped calculating and throwed a syntax error...
The underlying logic in my program is and was correct. Stargåte just put things right by explaining to me how to use
Bool() to make this new >PB> version understand it

Re: What? Bool() problem..
Posted: Sun Feb 24, 2013 10:54 pm
by Little John
utopiomania wrote:Stargåte just put things right by explaining to me how to use
Bool() to make this new >PB> version understand it

Yes, that's good. And your fine code can be even more improved. The following snippet yields exactly the same results as Stargate's code:
However, if you prefer you can also use e.g.
Code: Select all
N(1) = N(1) + Bool(Yr % 4 = 0) - 4 + 7 - 3
utopiomania wrote:The code calculated leap years correctly until newer versions of PB stopped calculating and throwed a syntax error...
I don't think that many people care whether you privately use some flawed code which just works by chance in particular cases.
But when you post wrong code in a
public forum, it shouldn't be too much of a surprise when someone corrects it.
Re: What? Bool() problem..
Posted: Sun Feb 24, 2013 11:21 pm
by utopiomania
I don't think that many people care whether you privately use some flawed code which just works by chance in particular cases.
But when you post wrong code in a public forum, it shouldn't be too much of a surprise when someone corrects it.
The algorithm and code is and was correct, and is not flawed, the problem had to do with syntax, not flawed logick or algorithms.
And, you are on my ignore list, so go away

Bye.
Re: What? Bool() problem..
Posted: Sun Feb 24, 2013 11:37 pm
by Little John
utopiomania wrote:The algorithm and code is and was correct, and is not flawed [...]
And, you are on my ignore list, so go away

Bye.
Obviously, logical thinking and sense of reality are also on your ignore list.

Boy, you made my day.
Re: What? Bool() problem..
Posted: Mon Feb 25, 2013 7:33 am
by Brandon Parker
For cimplicity's sake, to test for a leap year (within PB's applicable Date range) you could just use the built in Date() function
Returns -1 if the given Date() parameters do not exist....
Code: Select all
Debug Date(2013, 02, 29, 12, 00, 00)
;Returns -1
or
Returns the date value expressed by the passed parameters
Code: Select all
Debug Date(2013, 02, 28, 12, 00, 00)
;Returns 1362009600
That's how I would do it anyway....let PureBasic decide when a leap year exists.
{:0)
Brandon
Re: What? Bool() problem..
Posted: Mon Feb 25, 2013 7:44 am
by rsts
For cimplicity's sake, to test for a leap year you could just use the built in Date() function
For dates within the limits of PB's date functions.
Re: What? Bool() problem..
Posted: Mon Feb 25, 2013 7:53 am
by Brandon Parker
rsts wrote:For cimplicity's sake, to test for a leap year you could just use the built in Date() function
For dates within the limits of PB's date functions.
I thought that was a given.......
{:0)
Brandon
Re: What? Bool() problem..
Posted: Mon Feb 25, 2013 8:25 am
by rsts
Brandon Parker wrote:
I thought that was a given.......
{:0)
Brandon
It wasn't
in order to see the different results of both code snippets, try e.g. for year = 1900.
Re: What? Bool() problem..
Posted: Mon Feb 25, 2013 9:54 am
by Brandon Parker
rsts wrote:Brandon Parker wrote:
I thought that was a given.......
{:0)
Brandon
It wasn't
in order to see the different results of both code snippets, try e.g. for year = 1900.
Yeah.....while that quote is about something completely different; I get it. I just assumed that someone using the Date() function would know that what I posted wouldn't work outside of PB's applicable date range. I know.... I know.... one should not assume that anyone ever reads the documentation before trying something.....
{:0)
Brandon
Re: What? Bool() problem..
Posted: Tue Feb 26, 2013 9:55 pm
by utopiomania
The code I posted calculates leap years correctly from 1562 to 3999.
Re: What? Bool() problem..
Posted: Tue Feb 26, 2013 10:59 pm
by rsts
As Little John noted, it fails in some circumstances. e.g. 1900, which it reports as a leap year, but was not.
Little John's code is correct.
cheers