On IDL Version 7.0 (linux x86_64 m64) ABS does not work as expected. This has to do with the fact that IDL allows both 0 and -0 for floats and doubles.
Example:
IDL> print, 0., -0., ABS(0.), ABS(-0.)
Output:
0.00000 -0.00000 0.00000 -0.00000
Expected output:
0.00000 -0.00000 0.00000 0.00000
Reproducable: always
This "bug" (or can we call it a feature?) also exists in Version 6.4, Solaris (sunos sparc m64) and Version 6.4 (linux x86 m32). What I'm calling for is a fix for ABS, NOT a fix for the fact that -0. is a valid number and that it is stored that way. That is actually a very very useful feature if one uses coordinates in the DMS notation (i.e. -00d30m00.0s).
The way that one can distinguish between 0. and -0. is using byte-order swapping:
FUNCTION isneg, x
COMPILE_OPT STRICTARRSUBS, IDL2, HIDDEN
; Copyright E Westra 2008
; This software is provided as is without any warranty whatsoever.
; Permission to use, copy, modify, and distribute modified or
; unmodified copies is granted, provided this copyright and disclaimer
; are included unchanged.
;Determines if a value is negative or not. Negative is defined as
;being LT 0 OR -0. Since IDL can't distinguish 0 from -0
;endian-swapping helps in this case
;
;Testing shows that -0 only exists for types of floating or double
;precision
type = SIZE(x, /TYPE)
IF type NE 2 AND type NE 3 AND type NE 4 AND type NE 5 AND type NE 6 AND type NE 9 AND type NE 14 THEN message, 'Argument can only be of a signed type...'
isZero = (x EQ 0)
isNonzero = (SWAP_ENDIAN(x) NE 0)
isNegative = (x LT 0)
RETURN, (isZero AND isNonZero) OR (isNegative)
END
(code can be used but needs copyright statement in there!)
Some tests:
IDL> print, isneg(0.), isneg(-0.), -0. eq 0., -0. lt 0., -0. gt 0
0 1 1 0 0
What I find really funny here is that -0. is equal to 0., but that isneg(-0.) is not equal to isneg(0) (although, that's what isneg is designed to find out ;)).
|