in reply to Re: Interesting unary - oddity
in thread Interesting unary - oddity

Hmm, that means -bareword makes sense, which I don't disagree with.

My problem is with -"-key" being "+key". That's harder to justify, isn't it?


Mike

Replies are listed 'Best First'.
Re^3: Interesting unary - oddity
by sgifford (Prior) on Aug 27, 2004 at 18:01 UTC
    One possible explanation is that this implementation is mathematically equivalent to stripping the minus sign, but doesn't require changing the length of the string, which is somewhat faster. In C, switching the sign requires a single character write, while removing it requires making a new copy of the string that's one character shorter; even in Perl using substr, it's somewhat faster:
    Benchmark: timing 100000 iterations of switchsign, unsign... switchsign: 4 wallclock secs ( 1.37 usr + 0.00 sys = 1.37 CPU) @ 72992.70/s (n=100000) unsign: 4 wallclock secs ( 1.51 usr + 0.00 sys = 1.51 CPU) @ 66225.17/s (n=100000)