Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 94 additions & 17 deletions src/decimo/bigfloat/bigfloat.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ struct BigFloat(Comparable, Movable, Writable):
message=(
"BigFloat requires MPFR (brew install mpfr / apt"
" install libmpfr-dev)"
)
),
function="BigFloat.__init__()",
)
)
var bits = _dps_to_bits(precision)
Expand Down Expand Up @@ -468,7 +469,12 @@ struct BigFloat(Comparable, Movable, Writable):
"""
var h = mpfrw_init(_dps_to_bits(self.precision))
if h < 0:
raise Error(DecimoError(message="Handle allocation failed"))
raise Error(
DecimoError(
message="Handle allocation failed.",
function="BigFloat.__neg__()",
)
)
mpfrw_neg(h, self.handle)
return Self(_handle=h, _precision=self.precision)

Expand All @@ -480,7 +486,12 @@ struct BigFloat(Comparable, Movable, Writable):
"""
var h = mpfrw_init(_dps_to_bits(self.precision))
if h < 0:
raise Error(DecimoError(message="Handle allocation failed"))
raise Error(
DecimoError(
message="Handle allocation failed.",
function="BigFloat.__abs__()",
)
)
mpfrw_abs(h, self.handle)
return Self(_handle=h, _precision=self.precision)

Expand All @@ -500,7 +511,12 @@ struct BigFloat(Comparable, Movable, Writable):
var prec = max(self.precision, other.precision)
var h = mpfrw_init(_dps_to_bits(prec))
if h < 0:
raise Error(DecimoError(message="Handle allocation failed"))
raise Error(
DecimoError(
message="Handle allocation failed.",
function="BigFloat.__add__()",
)
)
mpfrw_add(h, self.handle, other.handle)
return Self(_handle=h, _precision=prec)

Expand All @@ -516,7 +532,12 @@ struct BigFloat(Comparable, Movable, Writable):
var prec = max(self.precision, other.precision)
var h = mpfrw_init(_dps_to_bits(prec))
if h < 0:
raise Error(DecimoError(message="Handle allocation failed"))
raise Error(
DecimoError(
message="Handle allocation failed.",
function="BigFloat.__sub__()",
)
)
mpfrw_sub(h, self.handle, other.handle)
return Self(_handle=h, _precision=prec)

Expand All @@ -532,7 +553,12 @@ struct BigFloat(Comparable, Movable, Writable):
var prec = max(self.precision, other.precision)
var h = mpfrw_init(_dps_to_bits(prec))
if h < 0:
raise Error(DecimoError(message="Handle allocation failed"))
raise Error(
DecimoError(
message="Handle allocation failed.",
function="BigFloat.__mul__()",
)
)
mpfrw_mul(h, self.handle, other.handle)
return Self(_handle=h, _precision=prec)

Expand All @@ -548,7 +574,12 @@ struct BigFloat(Comparable, Movable, Writable):
var prec = max(self.precision, other.precision)
var h = mpfrw_init(_dps_to_bits(prec))
if h < 0:
raise Error(DecimoError(message="Handle allocation failed"))
raise Error(
DecimoError(
message="Handle allocation failed.",
function="BigFloat.__truediv__()",
)
)
mpfrw_div(h, self.handle, other.handle)
return Self(_handle=h, _precision=prec)

Expand All @@ -575,7 +606,12 @@ struct BigFloat(Comparable, Movable, Writable):
"""
var h = mpfrw_init(_dps_to_bits(self.precision))
if h < 0:
raise Error(DecimoError(message="Handle allocation failed"))
raise Error(
DecimoError(
message="Handle allocation failed.",
function="BigFloat.sqrt()",
)
)
mpfrw_sqrt(h, self.handle)
return Self(_handle=h, _precision=self.precision)

Expand All @@ -587,7 +623,12 @@ struct BigFloat(Comparable, Movable, Writable):
"""
var h = mpfrw_init(_dps_to_bits(self.precision))
if h < 0:
raise Error(DecimoError(message="Handle allocation failed"))
raise Error(
DecimoError(
message="Handle allocation failed.",
function="BigFloat.exp()",
)
)
mpfrw_exp(h, self.handle)
return Self(_handle=h, _precision=self.precision)

Expand All @@ -599,7 +640,12 @@ struct BigFloat(Comparable, Movable, Writable):
"""
var h = mpfrw_init(_dps_to_bits(self.precision))
if h < 0:
raise Error(DecimoError(message="Handle allocation failed"))
raise Error(
DecimoError(
message="Handle allocation failed.",
function="BigFloat.ln()",
)
)
mpfrw_log(h, self.handle)
return Self(_handle=h, _precision=self.precision)

Expand All @@ -611,7 +657,12 @@ struct BigFloat(Comparable, Movable, Writable):
"""
var h = mpfrw_init(_dps_to_bits(self.precision))
if h < 0:
raise Error(DecimoError(message="Handle allocation failed"))
raise Error(
DecimoError(
message="Handle allocation failed.",
function="BigFloat.sin()",
)
)
mpfrw_sin(h, self.handle)
return Self(_handle=h, _precision=self.precision)

Expand All @@ -623,7 +674,12 @@ struct BigFloat(Comparable, Movable, Writable):
"""
var h = mpfrw_init(_dps_to_bits(self.precision))
if h < 0:
raise Error(DecimoError(message="Handle allocation failed"))
raise Error(
DecimoError(
message="Handle allocation failed.",
function="BigFloat.cos()",
)
)
mpfrw_cos(h, self.handle)
return Self(_handle=h, _precision=self.precision)

Expand All @@ -635,7 +691,12 @@ struct BigFloat(Comparable, Movable, Writable):
"""
var h = mpfrw_init(_dps_to_bits(self.precision))
if h < 0:
raise Error(DecimoError(message="Handle allocation failed"))
raise Error(
DecimoError(
message="Handle allocation failed.",
function="BigFloat.tan()",
)
)
mpfrw_tan(h, self.handle)
return Self(_handle=h, _precision=self.precision)

Expand All @@ -651,7 +712,12 @@ struct BigFloat(Comparable, Movable, Writable):
var prec = max(self.precision, exponent.precision)
var h = mpfrw_init(_dps_to_bits(prec))
if h < 0:
raise Error(DecimoError(message="Handle allocation failed"))
raise Error(
DecimoError(
message="Handle allocation failed.",
function="BigFloat.power()",
)
)
mpfrw_pow(h, self.handle, exponent.handle)
return Self(_handle=h, _precision=prec)

Expand All @@ -666,7 +732,12 @@ struct BigFloat(Comparable, Movable, Writable):
"""
var h = mpfrw_init(_dps_to_bits(self.precision))
if h < 0:
raise Error(DecimoError(message="Handle allocation failed"))
raise Error(
DecimoError(
message="Handle allocation failed.",
function="BigFloat.root()",
)
)
mpfrw_rootn_ui(h, self.handle, n)
return Self(_handle=h, _precision=self.precision)

Expand All @@ -686,11 +757,17 @@ struct BigFloat(Comparable, Movable, Writable):
message=(
"BigFloat requires MPFR (brew install mpfr / apt"
" install libmpfr-dev)"
)
),
function="BigFloat.pi()",
)
)
var h = mpfrw_init(_dps_to_bits(precision))
if h < 0:
raise Error(DecimoError(message="Handle allocation failed"))
raise Error(
DecimoError(
message="Handle allocation failed.",
function="BigFloat.pi()",
)
)
mpfrw_const_pi(h)
return BigFloat(_handle=h, _precision=precision)
3 changes: 3 additions & 0 deletions src/decimo/bigint/bigint.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ struct BigInt(
except e:
raise Error(
DecimoError(
message="See the above exception.",
function="BigInt.__floordiv__()",
previous_error=e^,
)
Expand All @@ -1006,6 +1007,7 @@ struct BigInt(
except e:
raise Error(
DecimoError(
message="See the above exception.",
function="BigInt.__mod__()",
previous_error=e^,
)
Expand All @@ -1026,6 +1028,7 @@ struct BigInt(
except e:
raise Error(
DecimoError(
message="See the above exception.",
function="BigInt.__divmod__()",
previous_error=e^,
)
Expand Down
6 changes: 6 additions & 0 deletions src/decimo/bigint10/arithmetics.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def floor_divide(x1: BigInt10, x2: BigInt10) raises -> BigInt10:
except e:
raise Error(
DecimoError(
message="See the above exception.",
function="floor_divide()",
previous_error=e^,
),
Expand All @@ -242,6 +243,7 @@ def floor_divide(x1: BigInt10, x2: BigInt10) raises -> BigInt10:
except e:
raise Error(
DecimoError(
message="See the above exception.",
function="floor_divide()",
previous_error=e^,
),
Expand Down Expand Up @@ -272,6 +274,7 @@ def truncate_divide(x1: BigInt10, x2: BigInt10) raises -> BigInt10:
except e:
raise Error(
DecimoError(
message="See the above exception.",
function="truncate_divide()",
previous_error=e^,
),
Expand Down Expand Up @@ -307,6 +310,7 @@ def floor_modulo(x1: BigInt10, x2: BigInt10) raises -> BigInt10:
except e:
raise Error(
DecimoError(
message="See the above exception.",
function="floor_modulo()",
previous_error=e^,
),
Expand All @@ -322,6 +326,7 @@ def floor_modulo(x1: BigInt10, x2: BigInt10) raises -> BigInt10:
except e:
raise Error(
DecimoError(
message="See the above exception.",
function="floor_modulo()",
previous_error=e^,
),
Expand Down Expand Up @@ -352,6 +357,7 @@ def truncate_modulo(x1: BigInt10, x2: BigInt10) raises -> BigInt10:
except e:
raise Error(
DecimoError(
message="See the above exception.",
function="truncate_modulo()",
previous_error=e^,
),
Expand Down
4 changes: 4 additions & 0 deletions src/decimo/bigint10/bigint10.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ struct BigInt10(
except e:
raise Error(
DecimoError(
message="See the above exception.",
function=(
"BigInt10.__init__(var words: List[UInt32], sign: Bool)"
),
Expand Down Expand Up @@ -231,6 +232,7 @@ struct BigInt10(
except e:
raise Error(
DecimoError(
message="See the above exception.",
function=(
"BigInt10.from_list(var words: List[UInt32], sign:"
" Bool)"
Expand Down Expand Up @@ -636,6 +638,7 @@ struct BigInt10(
except e:
raise Error(
DecimoError(
message="See the above exception.",
function="BigInt10.__floordiv__()",
previous_error=e^,
)
Expand All @@ -656,6 +659,7 @@ struct BigInt10(
except e:
raise Error(
DecimoError(
message="See the above exception.",
function="BigInt10.__mod__()",
previous_error=e^,
)
Expand Down
4 changes: 4 additions & 0 deletions src/decimo/biguint/arithmetics.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -3345,6 +3345,7 @@ def floor_modulo(x1: BigUInt, x2: BigUInt) raises -> BigUInt:
except e:
raise Error(
DecimoError(
message="See the above exception.",
function="floor_modulo()",
previous_error=e^,
)
Expand All @@ -3357,6 +3358,7 @@ def floor_modulo(x1: BigUInt, x2: BigUInt) raises -> BigUInt:
except e:
raise Error(
DecimoError(
message="See the above exception.",
function="floor_modulo()",
previous_error=e^,
)
Expand Down Expand Up @@ -3386,6 +3388,7 @@ def truncate_modulo(x1: BigUInt, x2: BigUInt) raises -> BigUInt:
except e:
raise Error(
DecimoError(
message="See the above exception.",
function="truncate_modulo()",
previous_error=e^,
)
Expand Down Expand Up @@ -3474,6 +3477,7 @@ def floor_divide_modulo(
except e:
raise Error(
DecimoError(
message="See the above exception.",
function="floor_divide_modulo()",
previous_error=e^,
)
Expand Down
Loading
Loading