December 06, 2003 complex comparison | ||||
---|---|---|---|---|
| ||||
Complex numbers cannot be ordered if they have imaginary parts. However, following program outputs "a > b" and "b !> a", i.e. a and b are ordered as "a > b". cdouble a = 1 + 2i, b = 2 + 3i; if(a > b) puts("a > b"); else puts("a !> b"); if(b > a) puts("b > a"); else puts("b !> a"); I've examined the behaviors in several cases, I guess then that "a > b" means "a.im < b.im || (a.im == b.im && a.re < b.re)". I wonder why such a confusing comparison method is used. I suggest that complex numbers shouldn't be ordered as NaN. (But, I think that pure imaginary numbers can be ordered as now.) Robert (Japanese) |
Copyright © 1999-2021 by the D Language Foundation