What? Bool() problem..

Just starting out? Need help? Post your questions and find answers here.
User avatar
skywalk
Addict
Addict
Posts: 4262
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: What? Bool() problem..

Post by skywalk »

What a load of bool :lol:

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)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Little John
Addict
Addict
Posts: 4812
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: What? Bool() problem..

Post 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. Image
ForEver
:lol:
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Re: What? Bool() problem..

Post 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.. :lol:
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: What? Bool() problem..

Post by rsts »

skywalk wrote:What a load of bool :lol:
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: What? Bool() problem..

Post 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
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Little John
Addict
Addict
Posts: 4812
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: What? Bool() problem..

Post 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.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Re: What? Bool() problem..

Post by utopiomania »

Utopiomania has many mismatches...
Ok, which mismatches ? :)
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: What? Bool() problem..

Post 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... :mrgreen:
quad variables for years
For eternal life, it is even not enough. :mrgreen:

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
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
skywalk
Addict
Addict
Posts: 4262
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: What? Bool() problem..

Post 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
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Re: What? Bool() problem..

Post 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???
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: What? Bool() problem..

Post by charvista »

Yes, it fails.
With PB 5.10, you *must* use the Bool() function.
You cannot run this code without Bool().
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Re: What? Bool() problem..

Post by utopiomania »

I know, I run it with Bool now, but does it fail with the Bool function and the last 'and' thingy..

Code: Select all

0) & (Yr
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: What? Bool() problem..

Post 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! :mrgreen:

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 :wink:
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Re: What? Bool() problem..

Post by utopiomania »

Sorry for this mess, seems I posted old code, this is the one in the working version,
with bool in place :oops:

Code: Select all

 bool(Yr % 4 = 0) & bool(Yr % 100 <> 0) | bool(Yr % 400 = 0)
Post Reply