All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rtc: Modify leap year test for more simpler way
@ 2013-02-06 11:22 Jonghwa Lee
  2013-02-06 11:42 ` Venu Byravarasu
  0 siblings, 1 reply; 7+ messages in thread
From: Jonghwa Lee @ 2013-02-06 11:22 UTC (permalink / raw)
  To: linux-kernel; +Cc: a.zummo, Andrew Morton, rtc-linux, Jonghwa Lee

Leap year which is multiple of 4, just needed 2 LSB for verifying.
A year with zero for all thease two bits means that it is leap year.

Signed-off-by: Jonghwa Lee <jonghwa3.lee@samsung.com>
---
 include/linux/rtc.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index 9531845..d662b8d 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -181,7 +181,7 @@ void rtc_timer_do_work(struct work_struct *work);
 
 static inline bool is_leap_year(unsigned int year)
 {
-	return (!(year % 4) && (year % 100)) || !(year % 400);
+	return !(year & 0x3);
 }
 
 #ifdef CONFIG_RTC_HCTOSYS_DEVICE
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* RE: [PATCH] rtc: Modify leap year test for more simpler way
  2013-02-06 11:22 [PATCH] rtc: Modify leap year test for more simpler way Jonghwa Lee
@ 2013-02-06 11:42 ` Venu Byravarasu
  2013-02-06 12:43   ` jonghwa3.lee
  0 siblings, 1 reply; 7+ messages in thread
From: Venu Byravarasu @ 2013-02-06 11:42 UTC (permalink / raw)
  To: Jonghwa Lee, linux-kernel; +Cc: a.zummo, Andrew Morton, rtc-linux

By definition, leap year is one, which is a divisible by 4 & 400, excluding multiples of 100s.
Hence I feel this patch is not correct.

Thanks,
Venu


> -----Original Message-----
> From: linux-kernel-owner@vger.kernel.org [mailto:linux-kernel-
> owner@vger.kernel.org] On Behalf Of Jonghwa Lee
> Sent: Wednesday, February 06, 2013 4:53 PM
> To: linux-kernel@vger.kernel.org
> Cc: a.zummo@towertech.it; Andrew Morton; rtc-linux@googlegroups.com;
> Jonghwa Lee
> Subject: [PATCH] rtc: Modify leap year test for more simpler way
> 
> Leap year which is multiple of 4, just needed 2 LSB for verifying.
> A year with zero for all thease two bits means that it is leap year.
> 
> Signed-off-by: Jonghwa Lee <jonghwa3.lee@samsung.com>
> ---
>  include/linux/rtc.h |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/rtc.h b/include/linux/rtc.h
> index 9531845..d662b8d 100644
> --- a/include/linux/rtc.h
> +++ b/include/linux/rtc.h
> @@ -181,7 +181,7 @@ void rtc_timer_do_work(struct work_struct *work);
> 
>  static inline bool is_leap_year(unsigned int year)
>  {
> -	return (!(year % 4) && (year % 100)) || !(year % 400);
> +	return !(year & 0x3);
>  }
> 
>  #ifdef CONFIG_RTC_HCTOSYS_DEVICE
> --
> 1.7.9.5
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] rtc: Modify leap year test for more simpler way
  2013-02-06 11:42 ` Venu Byravarasu
@ 2013-02-06 12:43   ` jonghwa3.lee
  2013-02-06 12:53     ` jonghwa3.lee
  2013-02-06 13:00     ` Haojian Zhuang
  0 siblings, 2 replies; 7+ messages in thread
From: jonghwa3.lee @ 2013-02-06 12:43 UTC (permalink / raw)
  To: Venu Byravarasu
  Cc: Jonghwa Lee, linux-kernel, a.zummo, Andrew Morton, rtc-linux

On 2013년 02월 06일 20:42, Venu Byravarasu wrote:
> By definition, leap year is one, which is a divisible by 4 & 400, excluding multiples of 100s.
> Hence I feel this patch is not correct.

No, I think you might misunderstood the it's meaning. The former code checks
whether if it is multiple of 4 or not. Formal mathematical way to verify multiple of 4
is just checks the last two digits are multiple of 4. This '(!year % 4) && (year % 100)'
part does it. But with only that checking, it may miss the case of multiple of 400 which
is also multiple of 4. Then my modification checks in hexadecimal, whether if number
has any of 1st and 2nd bit with value 1. Because any number which has all bits above
the 3rd can be divided with 4(2^2).
(e.g. 44(0b101100) = 2^5+2^3+2^2 = 2^2(2^3 + 2 + 1))
So It does same things with less instructions.
> Thanks,
> Venu
>
>
>> -----Original Message-----
>> From: linux-kernel-owner@vger.kernel.org [mailto:linux-kernel-
>> owner@vger.kernel.org] On Behalf Of Jonghwa Lee
>> Sent: Wednesday, February 06, 2013 4:53 PM
>> To: linux-kernel@vger.kernel.org
>> Cc: a.zummo@towertech.it; Andrew Morton; rtc-linux@googlegroups.com;
>> Jonghwa Lee
>> Subject: [PATCH] rtc: Modify leap year test for more simpler way
>>
>> Leap year which is multiple of 4, just needed 2 LSB for verifying.
>> A year with zero for all thease two bits means that it is leap year.
>>
>> Signed-off-by: Jonghwa Lee <jonghwa3.lee@samsung.com>
>> ---
>>  include/linux/rtc.h |    2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/linux/rtc.h b/include/linux/rtc.h
>> index 9531845..d662b8d 100644
>> --- a/include/linux/rtc.h
>> +++ b/include/linux/rtc.h
>> @@ -181,7 +181,7 @@ void rtc_timer_do_work(struct work_struct *work);
>>
>>  static inline bool is_leap_year(unsigned int year)
>>  {
>> -	return (!(year % 4) && (year % 100)) || !(year % 400);
>> +	return !(year & 0x3);
>>  }
>>
>>  #ifdef CONFIG_RTC_HCTOSYS_DEVICE
>> --
>> 1.7.9.5
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at  http://www.tux.org/lkml/
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] rtc: Modify leap year test for more simpler way
  2013-02-06 12:43   ` jonghwa3.lee
@ 2013-02-06 12:53     ` jonghwa3.lee
  2013-02-06 13:00     ` Haojian Zhuang
  1 sibling, 0 replies; 7+ messages in thread
From: jonghwa3.lee @ 2013-02-06 12:53 UTC (permalink / raw)
  To: Venu Byravarasu; +Cc: Alessandro Zummo, Andrew Morton, rtc-linux, linux-kernel

On 2013년 02월 06일 20:42, Venu Byravarasu wrote:
> By definition, leap year is one, which is a divisible by 4 & 400, excluding multiples of 100s.
> Hence I feel this patch is not correct.

No, I think you might misunderstood the it's meaning. The former code checks
whether if it is multiple of 4 or not. Formal mathematical way to verify multiple of 4
is just checks the last two digits are multiple of 4. This '(!year % 4) && (year % 100)'
part does it. But with only that checking, it may miss the case of multiple of 400 which
is also multiple of 4. That's why '!(year % 400)' part was needed.
Then my modification checks in hexadecimal, whether if number has any of 1st and 2nd bit
with value 1. Because any number which has all bits above the 3rd can be divided with 4(2^2).
(e.g. 44(0b101100) = 2^5+2^3+2^2 = 2^2(2^3 + 2 + 1)) So It does same things with
less instructions.

Thanks,
Jonghwa

> Thanks,
> Venu
>
>
>> -----Original Message-----
>> From: linux-kernel-owner@vger.kernel.org [mailto:linux-kernel-
>> owner@vger.kernel.org] On Behalf Of Jonghwa Lee
>> Sent: Wednesday, February 06, 2013 4:53 PM
>> To: linux-kernel@vger.kernel.org
>> Cc: a.zummo@towertech.it; Andrew Morton; rtc-linux@googlegroups.com;
>> Jonghwa Lee
>> Subject: [PATCH] rtc: Modify leap year test for more simpler way
>>
>> Leap year which is multiple of 4, just needed 2 LSB for verifying.
>> A year with zero for all thease two bits means that it is leap year.
>>
>> Signed-off-by: Jonghwa Lee <jonghwa3.lee@samsung.com>
>> ---
>>  include/linux/rtc.h |    2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/include/linux/rtc.h b/include/linux/rtc.h
>> index 9531845..d662b8d 100644
>> --- a/include/linux/rtc.h
>> +++ b/include/linux/rtc.h
>> @@ -181,7 +181,7 @@ void rtc_timer_do_work(struct work_struct *work);
>>
>>  static inline bool is_leap_year(unsigned int year)
>>  {
>> -	return (!(year % 4) && (year % 100)) || !(year % 400);
>> +	return !(year & 0x3);
>>  }
>>
>>  #ifdef CONFIG_RTC_HCTOSYS_DEVICE
>> --
>> 1.7.9.5
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at  http://www.tux.org/lkml/
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] rtc: Modify leap year test for more simpler way
  2013-02-06 12:43   ` jonghwa3.lee
  2013-02-06 12:53     ` jonghwa3.lee
@ 2013-02-06 13:00     ` Haojian Zhuang
  2013-02-06 18:11       ` Stephen Warren
  1 sibling, 1 reply; 7+ messages in thread
From: Haojian Zhuang @ 2013-02-06 13:00 UTC (permalink / raw)
  To: jonghwa3.lee
  Cc: Venu Byravarasu, linux-kernel, a.zummo, Andrew Morton, rtc-linux

On Wed, Feb 6, 2013 at 8:43 PM,  <jonghwa3.lee@samsung.com> wrote:
> On 2013년 02월 06일 20:42, Venu Byravarasu wrote:
>> By definition, leap year is one, which is a divisible by 4 & 400, excluding multiples of 100s.
>> Hence I feel this patch is not correct.
>
> No, I think you might misunderstood the it's meaning. The former code checks
> whether if it is multiple of 4 or not. Formal mathematical way to verify multiple of 4
> is just checks the last two digits are multiple of 4. This '(!year % 4) && (year % 100)'
> part does it. But with only that checking, it may miss the case of multiple of 400 which
> is also multiple of 4. Then my modification checks in hexadecimal, whether if number
> has any of 1st and 2nd bit with value 1. Because any number which has all bits above
> the 3rd can be divided with 4(2^2).
> (e.g. 44(0b101100) = 2^5+2^3+2^2 = 2^2(2^3 + 2 + 1))
> So It does same things with less instructions.

I still can't understand your logic.

Please check whether 200 year is leap year.

200(decimal) = 2b11001000

!(200 & 0x3) = 1 (Your condition said that 200 year is a leap year.)

According to this logic in below.
 if year mod 4 = 0 and year mod 100 <> 0 or year mod 400 = 0, then
it's a leap year.

This tells us that 200 year isn't a leap year because 200 mod 100 ==
0. So who is wrong?

Regards
Haojian

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] rtc: Modify leap year test for more simpler way
  2013-02-06 13:00     ` Haojian Zhuang
@ 2013-02-06 18:11       ` Stephen Warren
  2013-02-07  1:15         ` jonghwa3.lee
  0 siblings, 1 reply; 7+ messages in thread
From: Stephen Warren @ 2013-02-06 18:11 UTC (permalink / raw)
  To: Haojian Zhuang
  Cc: jonghwa3.lee, Venu Byravarasu, linux-kernel, a.zummo,
	Andrew Morton, rtc-linux

On 02/06/2013 06:00 AM, Haojian Zhuang wrote:
> On Wed, Feb 6, 2013 at 8:43 PM,  <jonghwa3.lee@samsung.com> wrote:
>> On 2013년 02월 06일 20:42, Venu Byravarasu wrote:
>>> By definition, leap year is one, which is a divisible by 4 & 400, excluding multiples of 100s.
>>> Hence I feel this patch is not correct.
>>
>> No, I think you might misunderstood the it's meaning. The former code checks
>> whether if it is multiple of 4 or not. Formal mathematical way to verify multiple of 4
>> is just checks the last two digits are multiple of 4. This '(!year % 4) && (year % 100)'
>> part does it. But with only that checking, it may miss the case of multiple of 400 which
>> is also multiple of 4. Then my modification checks in hexadecimal, whether if number
>> has any of 1st and 2nd bit with value 1. Because any number which has all bits above
>> the 3rd can be divided with 4(2^2).
>> (e.g. 44(0b101100) = 2^5+2^3+2^2 = 2^2(2^3 + 2 + 1))
>> So It does same things with less instructions.
> 
> I still can't understand your logic.
> 
> Please check whether 200 year is leap year.
> 
> 200(decimal) = 2b11001000
> 
> !(200 & 0x3) = 1 (Your condition said that 200 year is a leap year.)
> 
> According to this logic in below.
>  if year mod 4 = 0 and year mod 100 <> 0 or year mod 400 = 0, then
> it's a leap year.
> 
> This tells us that 200 year isn't a leap year because 200 mod 100 ==
> 0. So who is wrong?

The rule is: it's a leap year if divisible by 4, unless it's divisible
by 100, but actually also including years divisible by 400. So, the
current code is correct, and the patch is wrong.

http://en.wikipedia.org/wiki/Leap_year#Algorithm

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] rtc: Modify leap year test for more simpler way
  2013-02-06 18:11       ` Stephen Warren
@ 2013-02-07  1:15         ` jonghwa3.lee
  0 siblings, 0 replies; 7+ messages in thread
From: jonghwa3.lee @ 2013-02-07  1:15 UTC (permalink / raw)
  To: Stephen Warren
  Cc: Haojian Zhuang, Venu Byravarasu, linux-kernel, a.zummo,
	Andrew Morton, rtc-linux

On 2013년 02월 07일 03:11, Stephen Warren wrote:
> On 02/06/2013 06:00 AM, Haojian Zhuang wrote:
>> On Wed, Feb 6, 2013 at 8:43 PM,  <jonghwa3.lee@samsung.com> wrote:
>>> On 2013년 02월 06일 20:42, Venu Byravarasu wrote:
>>>> By definition, leap year is one, which is a divisible by 4 & 400, excluding multiples of 100s.
>>>> Hence I feel this patch is not correct.
>>>
>>> No, I think you might misunderstood the it's meaning. The former code checks
>>> whether if it is multiple of 4 or not. Formal mathematical way to verify multiple of 4
>>> is just checks the last two digits are multiple of 4. This '(!year % 4) && (year % 100)'
>>> part does it. But with only that checking, it may miss the case of multiple of 400 which
>>> is also multiple of 4. Then my modification checks in hexadecimal, whether if number
>>> has any of 1st and 2nd bit with value 1. Because any number which has all bits above
>>> the 3rd can be divided with 4(2^2).
>>> (e.g. 44(0b101100) = 2^5+2^3+2^2 = 2^2(2^3 + 2 + 1))
>>> So It does same things with less instructions.
>>
>> I still can't understand your logic.
>>
>> Please check whether 200 year is leap year.
>>
>> 200(decimal) = 2b11001000
>>
>> !(200 & 0x3) = 1 (Your condition said that 200 year is a leap year.)
>>
>> According to this logic in below.
>>  if year mod 4 = 0 and year mod 100 <> 0 or year mod 400 = 0, then
>> it's a leap year.
>>
>> This tells us that 200 year isn't a leap year because 200 mod 100 ==
>> 0. So who is wrong?
> 
> The rule is: it's a leap year if divisible by 4, unless it's divisible
> by 100, but actually also including years divisible by 400. So, the
> current code is correct, and the patch is wrong.
> 

Sorry, I was wrong. I didn't know the definition of leap year not including
multiple of 4. Sorry for making noise.

Thanks,
Jonghwa


> http://en.wikipedia.org/wiki/Leap_year#Algorithm
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-02-07  1:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-06 11:22 [PATCH] rtc: Modify leap year test for more simpler way Jonghwa Lee
2013-02-06 11:42 ` Venu Byravarasu
2013-02-06 12:43   ` jonghwa3.lee
2013-02-06 12:53     ` jonghwa3.lee
2013-02-06 13:00     ` Haojian Zhuang
2013-02-06 18:11       ` Stephen Warren
2013-02-07  1:15         ` jonghwa3.lee

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.