Jump to content

Category talk:Wren-big: Difference between revisions

→‎Source code: BigRat.fromDecimal method can now deal with scientific notation.
(→‎Source code: Added zero fill option to BigRat.toDecimal method.)
(→‎Source code: BigRat.fromDecimal method can now deal with scientific notation.)
Line 1,372:
if (!(s is String)) s = s.toString
if (s == "") Fiber.abort("Argument cannot be an empty string.")
s = sBigInt.trimlower_().trim("0"s)
var parts = s.split("e")
if (parts.count > 2) Fiber.abort("Argument is invalid scientific notation.")
if (parts.count == 2) {
var isPositive = true
if (parts[1][0] == "-") {
parts[1] = parts[1][1..-1]
isPositive = false
}
if (parts[1][0] == "+") parts[1] = parts[1][1..-1]
var significand = fromDecimal(parts[0])
var p = BigInt.new(parts[1])
var exponent = BigRat.new(BigInt.ten.pow(p), BigInt.one)
return (isPositive) ? significand * exponent : significand / exponent
}
s = s.trim().trimStart("0")
if (s == "") return BigRat.zero
if (s.startsWith(".")) s = "0" + s
if (!s.contains(".")) return BigRat.new(s){
return BigRat.new(s)
} else {
s = s.trimEnd("0")
}
if (s.endsWith(".")) return BigRat.new(s[0..-2])
var splits = s.split(".")
9,482

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.