Odd use of sign

TorgoX on 2003-03-16T12:53:40

Dear All,

From the RTF spec:

\abshN -- N is the height of the frame in twips. A positive number indicates the minimum height of the frame, and a negative number indicates the exact height of the frame. A value of zero indicates that the height of the frame adjusts to the contents of the frame. This is the default for frames where no height is given.
have you ever seen this sort of thing in an API where a positive value in a parameter means one thing and negative value means something very different?


What about roll-over?

Beatnik on 2003-03-16T13:37:16

What happens when that one positive value rolls over into another negative value? :) Anarchy? Chaos?

Positive / Negative values

ziggy on 2003-03-16T16:00:05

Have you ever seen this sort of thing in an API where a positive value in a parameter means one thing and negative value means something very different?
I'm pretty sure I have, but I don't remember where. It may have been another MSAPI, which would confirm this example as an instance of MSThinking 1.0.

This seems like the kind of trickery a newbie C hacker would use in the days when they're being too clever by half. Especially something that would have been common in the early 1990s when C was starting to catch on big time in the microcomputing world.

Thankfully, those days don't last very long (or there would be all sorts of other trickery hanging on the boolean nature of the sign bit.) Unfortunately, sometimes those tricks make it into public APIs.

find

jmm on 2003-03-17T22:03:24

Not quite the same but time range arguments to find are absolute if there is no sign, or ranges if there is a sign (+ and - are interpreted as > and <).

So, -atime 5 means accessed 5 days ago, -atime -5 means accessed less than 5 days ago, and -atime +5 means accessed more than 5 days ago. Most of the time, you want a signed version. (How often do you want to find files used exactly 37 days ago, and be sure it wasn't 36 or 38?)

Sure... even in Perl!

bart on 2003-03-18T16:41:50

have you ever seen this sort of thing in an API where a positive value in a parameter means one thing and negative value means something very different?
I can give you two examples in Perl.
  1. (s)sprintf templates, "%10s" vs. "%-10s"... where one means align to the left, the other, align to the right.
  2. substr, where negative numbers for a numerical parameter mean from the end. In particular, check out the third parameter, LENGTH, which is not a length but the end offset (from the end) if it's negative.
    $s = join "", "A" .. "Z";
    print substr($s, 10, -10);
    Result:
    KLMNOP