Bug: date.cpp

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug: date.cpp

Gilbert Peffer
I found a slightly more serious bug in Date::year(), unless it was an
intended behaviour.

I think the function only works correctly (explained below what that means),
if you calculate the year using

        Year y = (theSerialNumber - 1)/365.25

The function, from my point of view, should at least implement the
year-change correctly. A little example using the 31/12/1999 and 1/1/2000
shows that the current function doesn't and the proposed one does:

    31/12/1999     resulting in     2000.0657... (current)
                   resulting in     1999.9972... (new)

    1/1/2000       resulting in     2000.0712... (current)
                   resulting in     2000         (new)

The integer part of the current version indicates that you are in the year
2000, although you are actually still in 1999. The proposed function
switches correctly.

Gilbert




Reply | Threaded
Open this post in threaded view
|

Re: Bug: date.cpp

Luigi Ballabio-3
At 12:39 PM 12/21/00 +0100, Gilbert Peffer wrote:

>I found a slightly more serious bug in Date::year(), unless it was an
>intended behaviour.
>
>I think the function only works correctly (explained below what that means),
>if you calculate the year using
>
>         Year y = (theSerialNumber - 1)/365.25
>
>The function, from my point of view, should at least implement the
>year-change correctly. A little example using the 31/12/1999 and 1/1/2000
>shows that the current function doesn't and the proposed one does:
>
>     31/12/1999     resulting in     2000.0657... (current)
>                    resulting in     1999.9972... (new)
>
>     1/1/2000       resulting in     2000.0712... (current)
>                    resulting in     2000         (new)

Hi Gilbert,
         in this case

Year y = theSerialNumber/365;

only gives a first guess. The two lines below, namely,

while (theSerialNumber < yearOffset[y])
     y--;

check the correctness of the guess and set y to the right value.
I agree that

>Year y = (theSerialNumber - 1)/365.25

might be a better guess. However, I'd like to leave the check, just in case
(365.25 isn't the exact value either)

Bye,
         Luigi



Reply | Threaded
Open this post in threaded view
|

Re: Bug: date.cpp

Ferdinando Ametrano-6
In reply to this post by Gilbert Peffer
>I agree that
>
>>Year y = (theSerialNumber - 1)/365.25
>
>might be a better guess. However, I'd like to leave the check, just in
>case (365.25 isn't the exact value either)
365.25 implies a couple of casting int->double->int that cannot be left
implict (coding guidelines no. 45 http://www.geosoft.no/style.html#Types ;-)

ciao -- Nando