Page 2 of 2
Re: What? Bool() problem..
Posted: Tue Feb 26, 2013 11:15 pm
by skywalk
What a load of bool
Code: Select all
Macro IsLeapYeard(Year)
Bool(Date(Year, 02, 29, 12, 00, 00) <> -1)
EndMacro
Macro IsLeapYear(Year)
Bool(Bool(Not (Year) % 4) And Bool((Year) % 100 Or Not (Year) % 400))
EndMacro
Define.i Year
Year = 1600 ; 1
Debug IsLeapYear(Year)
Debug IsLeapYeard(Year)
Year = 2096 ; 1
Debug IsLeapYear(Year)
Debug IsLeapYeard(Year)
Year = 2100 ; 0
Debug IsLeapYear(Year)
Debug IsLeapYeard(Year)
Year = 2800 ; 1
Debug IsLeapYear(Year)
Debug IsLeapYeard(Year)
Year = 3000 ; 0
Debug IsLeapYear(Year)
Debug IsLeapYeard(Year)
Re: What? Bool() problem..
Posted: Wed Feb 27, 2013 12:52 am
by Little John
Rumpelstiltskin wrote:My code is correct.
My code is correct.
My code is correct.
I do not want to read something.
I do not want to take note of facts.
I do not want to learn something.
I just want to tell you:
Repeat
My code is correct.
ForEver

Re: What? Bool() problem..
Posted: Wed Feb 27, 2013 11:01 pm
by utopiomania
Sorry typo, N(1) = N(1) + (Yr % 4 = 0) | (Yr % 100 = 0) & (Yr % 400 = 0)
Problem was that PB stopped at this expression, not my own typo..

Re: What? Bool() problem..
Posted: Thu Feb 28, 2013 1:02 am
by rsts
skywalk wrote:What a load of bool
Re: What? Bool() problem..
Posted: Sat Mar 02, 2013 9:32 pm
by charvista
I am using the Leap year check from Little John that I got in February 2011, looks different because using Mod() instead of the % operator, but it is the same; and even checking year 4000! Not sure if I added it myself or not?!
Code: Select all
If (Mod(Year.i,4)=0 And Mod(Year.i,100)<>0) Or (Mod(Year.i,400)=0 And Mod(Year.i,4000)<>0) then it is a Leap year.
Added a formule comparison:
Code: Select all
For year=1562 To 4001
a=Bool((year % 4 = 0 And year % 100 <> 0) Or year % 400 = 0)
b=Bool(Bool(Mod(Year.i,4)=0 And Mod(Year.i,100)<>0) Or Bool(Mod(Year.i,400)=0 And Mod(Year.i,4000)<>0))
c=Bool(Year % 4 = 0) | Bool(Year % 100 = 0) & Bool(Year % 400 = 0)
If a=b And b=c
Debug Str(year)+": ok"
Else
Debug "Mismatch at year "+Str(year)+" ("+Str(a)+","+Str(b)+","+Str(c)+")"
EndIf
Next
Utopiomania has many mismatches...
Cheers
Re: What? Bool() problem..
Posted: Sat Mar 02, 2013 10:32 pm
by Little John
charvista wrote:I am using the Leap year check from Little John that I got in February 2011, looks different because using Mod() instead of the % operator, but it is the same; and even checking year 4000! Not sure if I added it myself or not?!
I can tell you that you changed it yourself.

I always used % in this context, not Mod(). Because I always use integer or quad variables for years, and for these using % is appropriate. Mod() is for floating point values.
Re: What? Bool() problem..
Posted: Sat Mar 02, 2013 11:24 pm
by utopiomania
Utopiomania has many mismatches...
Ok, which mismatches ?

Re: What? Bool() problem..
Posted: Sun Mar 03, 2013 12:53 am
by charvista
I can tell you that you changed it yourself.

Much possible, I don't remember, the year 4000 is a long time ago now...
quad variables for years
For eternal life, it is even not enough.
The discussion seems endless, but there is a problem in the concept. The years 1700,1800,1900, 2100,2200,2300, 2500,2600,2700, 2900, etc.
are NOT leap years and your formule says that it is (they output 1 to the variable L).
Code: Select all
For year=1562 To 3000
L=Bool(Year % 4 = 0) | Bool(Year % 100 = 0) | Bool(Year % 400 = 0)
Debug Str(year)+": "+Str(L)
Next
For more info, see:
http://en.wikipedia.org/wiki/Leap_year
Re: What? Bool() problem..
Posted: Sun Mar 03, 2013 1:39 am
by skywalk
utopiomania wrote:Utopiomania has many mismatches...
Ok, which mismatches ?

Seriously, are you trolling?
Code: Select all
Macro IsLeapYear(Year)
Bool(Bool(Not (Year) % 4) And Bool((Year) % 100 Or Not (Year) % 400))
EndMacro
For year=1564 To 3000 Step 4
If Not IsLeapYear(Year)
Debug Str(year) + " <> Leap Year"
EndIf
Next
Re: What? Bool() problem..
Posted: Sun Mar 03, 2013 11:03 pm
by utopiomania
Code: Select all
Sorry typo, N(1) = N(1) + (Yr % 4 = 0) | (Yr % 100 = 0) & (Yr % 400 = 0)
What mismatches ? Does the code above fail???
Re: What? Bool() problem..
Posted: Sun Mar 03, 2013 11:22 pm
by charvista
Yes, it fails.
With PB 5.10, you *must* use the Bool() function.
You cannot run this code without Bool().
Re: What? Bool() problem..
Posted: Sun Mar 03, 2013 11:37 pm
by utopiomania
I know, I run it with Bool now, but does it fail with the Bool function and the last 'and' thingy..
Re: What? Bool() problem..
Posted: Mon Mar 04, 2013 1:02 am
by charvista
If you mean this:
Code: Select all
For year=1564 To 3000
Debug Str(year)+": "+Str(Bool(Yr % 4 = 0) | Bool(Yr % 100 = 0) & Bool(Yr % 400 = 0))
Next
Then it fails, it is even worse, because it returns always 1, telling that EACH year is a leap year! I wish it was true, so we could live longer!
Utopiomania, why don't you use this one, which is correct:
Code: Select all
N(1) = N(1) + Bool(Bool(Not Year % 4) And Bool(Year % 100 Or Not Year % 400))
it takes in account the exceptions of the years 1700,1800,1900,2100,2200,2300,2500,2600,2700, etc

Re: What? Bool() problem..
Posted: Thu Mar 07, 2013 6:30 pm
by utopiomania
Sorry for this mess, seems I posted old code, this is the one in the working version,
with bool in place
Code: Select all
bool(Yr % 4 = 0) & bool(Yr % 100 <> 0) | bool(Yr % 400 = 0)