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
6 changes: 5 additions & 1 deletion mojoproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ t = "clear && magic run test"
bench = "magic run package && cd benches && magic run mojo bench.mojo && cd .."
b = "clear && magic run bench"

# individual bench files
b_mul = "magic run package && cd benches && magic run mojo bench_multiply.mojo && cd .."
b_div = "magic run package && cd benches && magic run mojo bench_divide.mojo && cd .."

# before commit
final = "magic run test && magic run bench"
f = "clear && magic run final"

[dependencies]
max = ">=25.1,<25.3"
max = ">=25.1,<25.3"
16 changes: 14 additions & 2 deletions src/decimojo/decimal.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ struct Decimal(
fn __rsub__(self, other: Int) raises -> Self:
return decimojo.subtract(Decimal(other), self)

fn __mul__(self, other: Decimal) -> Self:
fn __mul__(self, other: Decimal) raises -> Self:
"""
Multiplies two Decimal values and returns a new Decimal containing the product.
"""
Expand All @@ -886,7 +886,7 @@ struct Decimal(
fn __mul__(self, other: Float64) raises -> Self:
return decimojo.multiply(self, Decimal(other))

fn __mul__(self, other: Int) -> Self:
fn __mul__(self, other: Int) raises -> Self:
return decimojo.multiply(self, Decimal(other))

fn __truediv__(self, other: Decimal) raises -> Self:
Expand Down Expand Up @@ -1133,6 +1133,18 @@ struct Decimal(
"""Returns True if this Decimal is NaN (Not a Number)."""
return (self.flags & Self.NAN_MASK) != 0

fn is_uint32able(self) -> Bool:
"""
Returns True if the coefficient can be represented as a UInt32 value.
"""
return self.high == 0 and self.mid == 0

fn is_uint64able(self) -> Bool:
"""
Returns True if the coefficient can be represented as a UInt64 value.
"""
return self.high == 0

fn scale(self) -> Int:
"""Returns the scale (number of decimal places) of this Decimal."""
return Int((self.flags & Self.SCALE_MASK) >> Self.SCALE_SHIFT)
Expand Down
Loading