in reply to Applying Sign Bit

Well, it's wierd that Date::Calc is doing that - returning a value of -0 that is. Because you cannot test for +0 or -0, think about it, 0 is zero. Add 1 to it and +0 becomes one, but so does minus 0. In fact the returned value has no significance or value, so you bneed to ask "why is Date::Calc returning a nonense value?". It may in fact mean that you are calling it invalidly and it is trying to DWIM with your request.

Maybe a code fragment that illustrates the situation would be helpful.

jdtoronto

Replies are listed 'Best First'.
Re: Applying Sign Bit
by Abigail-II (Bishop) on Jan 22, 2004 at 15:09 UTC
    so you bneed to ask "why is Date::Calc returning a nonense value?"
    No. The question to ask is What is Date::Calc returning?. What you do know is that it appears as -0 when printed. It could be a string. It could be an overloaded object. But since Date::Calc deals with numbers, it's probably a number. Now, we all know that floats can't always be represented exactly. So, could it be that -0 represents a small negative value, small enough that it stringifies to -0? Let's try:
    $ perl -wle 'print -1 / (10 ** 5000)' -0 $
    I guess it can.

    Note that the code of the OP was using -0 literals, which are a totally different kind of beast.

    Abigail

Re: Re: Applying Sign Bit
by budman (Sexton) on Jan 23, 2004 at 03:55 UTC

    When comparing 2 dates the DateCalc(d1,d2) function will return +0:0:WW:HH:MM:SS if the d2 > d1, and -0:0:WW:HH:MM:SS if d1 > d2. I think that is return type 0, and there is another return type that shows Years, Months, Days.

    If that return value was +1 or -1 then you can just multiple each item with the "flag" to apply the sign bit. I call it a flag, because it only has 2 states -0 or +0.

    Thanks for all the suggestions. I thought I might have overlooked a command that would do this. In the program, I opted to use another method of testings that proved to be more efficient. However, this applying a sign bit bugged me. I just needed to know. :) For future reference and to ease my mind.

    Here is another, shouldn't 1 + -0 = -1 ?

    budman
      shouldn't 1 + -0 = -1 ?
      No. If you subtracted 1 from each side, you'd have 0 + -0 = -2. That would be bizarre.