import sequtils,strutils,math type decimal = tuple[i : int64,f : float64] proc `+` (x,y : decimal) : decimal= result.f = x.f + y.f result.i = x.i + y.i if result.f < 0: result.f = round(result.f - 1e-13,13) else: result.f = round(result.f,12) result.i += result.f.int result.f -= result.f.int.float64 proc `$` (x : decimal):string = var s = "" if x.f < 0: if x.i < 0: s &= $x.i var n = formatBiggestFloat(x.f,ffDecimal,10) n = n[2..n.high] s &= n elif x.i == 0: s = formatBiggestFloat(x.f,ffDecimal,10) else: s &= $(x.i - 1) var n = formatBiggestFloat(x.f + 1.0,ffDecimal,10) n = n[1..n.high] s &= n if x.f >= 0: if x.i == -1: s = formatBiggestFloat(x.f,ffDecimal,10) if x.i < -1: s = $(x.i + 1) var n = formatBiggestFloat(x.f - 1.0,ffDecimal,10) n = n[2..n.high] s &= n else: s = $x.i var n = formatBiggestFloat(x.f,ffDecimal,10) n = n[1..n.high] s &= n return s proc parseDec(s : string):decimal= var i = s.find('.') if i == -1: result.i = s.parseBiggestInt else: result.i = s[0..