Category talk:Wren-fmt: Difference between revisions
Content added Content deleted
m (→Source code: Removed a commented-out line.) |
(→Source code: Added 'zp' format for complex numbers.) |
||
Line 568: | Line 568: | ||
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 = f(w, n.real, p) |
var real = f(w, n.real, p) |
||
var sign = (n.imag >= 0) ? " + " : " - " |
|||
var imag = f(w, n.imag.abs, p) |
|||
if (w < 0) imag = imag.trimEnd(" ") |
|||
return real + sign + imag + "i" |
|||
} |
|||
// Applies the 'fp' and 'f' formats respectively to each component, x and y, of a |
|||
// complex number 'n' before joining them together in the form x ± yi. |
|||
static zp(w, n, p) { |
|||
if (n is Num) return fp(w, n, p) |
|||
if (n.type.toString != "Complex") Fiber.abort("Argument must be a complex or real number.") |
|||
var real = fp(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) |
||
Line 601: | Line 613: | ||
static gp(w, n) { gp(w, n, precision) } |
static gp(w, n) { gp(w, n, precision) } |
||
static hp(w, n) { hp(w, n, precision) } |
static hp(w, n) { hp(w, n, precision) } |
||
static zp(w, n) { zp(w, n, precision) } |
|||
static fm(w, n) { fm(w, n, precision) } |
static fm(w, n) { fm(w, n, precision) } |
||
static gm(w, n) { gm(w, n, precision) } |
static gm(w, n) { gm(w, n, precision) } |
||
Line 659: | Line 672: | ||
(fn == "gp") ? gp(w, v, p) : |
(fn == "gp") ? gp(w, v, p) : |
||
(fn == "hp") ? hp(w, v, p) : |
(fn == "hp") ? hp(w, v, p) : |
||
(fn == "zp") ? zp(w, v, p) : |
|||
(fn == "fm") ? fm(w, v, p) : |
(fn == "fm") ? fm(w, v, p) : |
||
(fn == "gm") ? gm(w, v, p) : |
(fn == "gm") ? gm(w, v, p) : |
||
Line 680: | Line 694: | ||
// The parameters to be passed to the method are specified in 'w' and 'p' |
// The parameters to be passed to the method are specified in 'w' and 'p' |
||
// 'p' is needed for 'e', 'E', 'f', 'g', 'h', 'j', 'l', 'z', 'fz', 'gz', 'hz', 'fp', 'gp', |
// 'p' is needed for 'e', 'E', 'f', 'g', 'h', 'j', 'l', 'z', 'fz', 'gz', 'hz', 'fp', 'gp', |
||
// 'hp', 'fm', 'gm', 'hm', 'zm', 'fc', 'gc', 'hc', 'jc' or 'lc' but is ignored otherwise. |
// 'hp', 'zp', 'fm', 'gm', 'hm', 'zm', 'fc', 'gc', 'hc', 'jc' or 'lc' but is ignored otherwise. |
||
// The resulting strings are then joined together using the separator 'sep'. |
// The resulting strings are then joined together using the separator 'sep'. |
||
// having first applied the 'q' method, with parameter 'cc', to each of them. |
// having first applied the 'q' method, with parameter 'cc', to each of them. |
||
Line 758: | Line 772: | ||
// a, b, c, d, e, E, f, F, g, h, i, I, j, k, l, m, n, N, o, O, P, q, r, R, s, S, t, u, x, X, y or z. |
// a, b, c, d, e, E, f, F, g, h, i, I, j, k, l, m, n, N, o, O, P, q, r, R, s, S, t, u, x, X, y or z. |
||
// If present, the flag (there can only be one) must be one of the following: |
// If present, the flag (there can only be one) must be one of the following: |
||
// + always prints a + or - sign ('dp', 'fp', 'gp' or ' |
// + always prints a + or - sign ('dp', 'fp', 'gp', 'hp' or 'zp' methods) |
||
// (space) leaves a space for the sign but only prints minus ('dm', 'fm', 'gm', 'hm' or 'zm' methods) |
// (space) leaves a space for the sign but only prints minus ('dm', 'fm', 'gm', 'hm' or 'zm' methods) |
||
// , commatizes the following number ('dc', 'rc', 'sc', 'ic', 'fc', 'gc, 'hc', 'jc' or 'lc' methods) |
// , commatizes the following number ('dc', 'rc', 'sc', 'ic', 'fc', 'gc, 'hc', 'jc' or 'lc' methods) |
||
Line 874: | Line 888: | ||
fn = "dc" |
fn = "dc" |
||
} |
} |
||
} else if ((fn == "f" || fn == "g" || fn == "h") && plus) { |
} else if ((fn == "f" || fn == "g" || fn == "h" || fn == "z") && plus) { |
||
fn = fn + "p" |
fn = fn + "p" |
||
} else if ((fn == "f" || fn == "g" || fn == "h" || fn == "z") && space) { |
} else if ((fn == "f" || fn == "g" || fn == "h" || fn == "z") && space) { |