Category talk:Wren-complex: Difference between revisions
→Source code: Negative zero woes :(
(→Source code: Added methods to test for integerness.) |
(→Source code: Negative zero woes :() |
||
Line 306:
// Returns the string representation of this Complex object depending on 'showAsReal'.
toString {
if (_real == -0) _real = 0
if (_imag == -0) _imag = 0
var s = (_imag >= 0) ? "%(_real) + %(_imag)" : "%(_real) - %(-_imag)"
s = (_imag.abs != 1) ? s + "i" : s[0..-2] + "i"
if (s.endsWith("- 0i")) s = s[0..-5] + "+ 0i"
return (Complex.showAsReal && _imag == 0) ? s = s[0..-6] : s
|