Category talk:Wren-big: Difference between revisions

Content added Content deleted
(→‎Source code: BigRat.fromDecimal method can now deal with scientific notation.)
(→‎Source code: Bug fix.)
Line 1,559: Line 1,559:
if (zfill.type != Bool) Fiber.abort("Zfill must be true or false.")
if (zfill.type != Bool) Fiber.abort("Zfill must be true or false.")
var qr = _n.divMod(_d)
var qr = _n.divMod(_d)
var intPart = qr[0].toString
if (this.isNegative && qr[0] == 0) intPart = "-" + intPart
var rem = BigRat.new(qr[1].abs, _d)
var rem = BigRat.new(qr[1].abs, _d)
// need to allow an extra digit if 'rounding' is true
// need to allow an extra digit if 'rounding' is true
Line 1,570: Line 1,568:
if (finalByte >= 53) { // last character >= 5
if (finalByte >= 53) { // last character >= 5
decPart = (BigInt.new(decPart) + 5).toString
decPart = (BigInt.new(decPart) + 5).toString
if (digits == 0) qr[0] = isNegative ? qr[0].dec : qr[0].inc
}
}
decPart = decPart[0...-1] // remove last digit
decPart = decPart[0...-1] // remove last digit
Line 1,580: Line 1,579:
}
}
if (digits < 1) decPart = ""
if (digits < 1) decPart = ""
var intPart = qr[0].toString
if (this.isNegative && qr[0] == 0) intPart = "-" + intPart
if (decPart == "") return intPart + (zfill ? "." + ("0" * digits) : "")
if (decPart == "") return intPart + (zfill ? "." + ("0" * digits) : "")
return intPart + "." + decPart + (zfill ? ("0" * (digits - decPart.count)) : "")
return intPart + "." + decPart + (zfill ? ("0" * (digits - decPart.count)) : "")
}
}