Category talk:Wren-fmt: Difference between revisions
Content added Content deleted
(→Source code: Some minor improvements.) |
(→Source code: Changes to complex number formatting.) |
||
Line 481: | Line 481: | ||
} |
} |
||
// Applies the 'f' |
// Applies the 'fm' and 'f' formats respectively to each component, x and y, of a |
||
// before joining them together in the form x ± yi. |
// complex number 'n' before joining them together in the form x ± yi. |
||
static z(w, n, p) { |
static z(w, n, p) { |
||
if (n is Num) return f(w, n, p) |
if (n is Num) return f(w, n, p) |
||
if (n.type.toString != "Complex") Fiber.abort("Argument must be a complex or real number.") |
if (n.type.toString != "Complex") Fiber.abort("Argument must be a complex or real number.") |
||
var real = |
var real = fm(w, n.real, p) |
||
var sign = (n.imag >= 0) ? " + " : " - " |
var sign = (n.imag >= 0) ? " + " : " - " |
||
var imag = f(w, n.imag.abs, p) |
var imag = f(w, n.imag.abs, p) |
||
if (w < 0) imag = imag.trimEnd(" ") |
|||
return real + sign + imag + "i" |
return real + sign + imag + "i" |
||
} |
} |