Skip to content
Merged
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
14 changes: 7 additions & 7 deletions noir_stdlib/src/uint128.nr
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl U128 {
}

impl Add for U128 {
pub fn add(self: Self, b: U128) -> U128 {
fn add(self: Self, b: U128) -> U128 {
let low = self.lo + b.lo;
let lo = low as u64 as Field;
let carry = (low - lo) / pow64;
Expand All @@ -161,7 +161,7 @@ impl Add for U128 {
}

impl Sub for U128 {
pub fn sub(self: Self, b: U128) -> U128 {
fn sub(self: Self, b: U128) -> U128 {
let low = pow64 + self.lo - b.lo;
let lo = low as u64 as Field;
let borrow = (low == lo) as Field;
Expand All @@ -176,7 +176,7 @@ impl Sub for U128 {
}

impl Mul for U128 {
pub fn mul(self: Self, b: U128) -> U128 {
fn mul(self: Self, b: U128) -> U128 {
assert(self.hi*b.hi == 0, "attempt to multiply with overflow");
let low = self.lo*b.lo;
let lo = low as u64 as Field;
Expand All @@ -196,7 +196,7 @@ impl Mul for U128 {
}

impl Div for U128 {
pub fn div(self: Self, b: U128) -> U128 {
fn div(self: Self, b: U128) -> U128 {
let (q,r) = self.unconstrained_div(b);
let a = b * q + r;
assert_eq(self, a);
Expand All @@ -206,7 +206,7 @@ impl Div for U128 {
}

impl Rem for U128 {
pub fn rem(self: Self, b: U128) -> U128 {
fn rem(self: Self, b: U128) -> U128 {
let (q,r) = self.unconstrained_div(b);
let a = b * q + r;
assert_eq(self, a);
Expand All @@ -216,7 +216,7 @@ impl Rem for U128 {
}

impl Eq for U128 {
pub fn eq(self: Self, b: U128) -> bool {
fn eq(self: Self, b: U128) -> bool {
(self.lo == b.lo) & (self.hi == b.hi)
}
}
Expand Down Expand Up @@ -289,4 +289,4 @@ impl Shr for U128 {
}
self / U128::from_integer(y)
}
}
}