Skip to content

Commit dbafac4

Browse files
add neg and equals and update tests
1 parent 3946719 commit dbafac4

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

sdk/tests/arithmetic.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,13 @@ describe('Field and Group Arithmetic Tests', () => {
122122

123123
expect(sum.toString()).equals("84i8");
124124
expect(diff.toString()).equals("0i8");
125-
expect(prod.toString()).equals("1764i8");
125+
expect(prod.toString()).equals("-28i8");
126126
expect(quot.toString()).equals("1i8");
127127

128128
const int = I8.fromString("42i8");
129129
const plaintext = int.toPlaintext();
130130
expect(plaintext.toString()).equal("42i8");
131131

132-
133-
const original = I8.fromString("12i8");
134-
const scalar = original.toScalar();
135-
const field = scalar.toField();
136-
const recreated = I8.fromField(field);
137-
expect(recreated.toString()).equal("12i8");
138-
139132
const f = Field.fromString("12field");
140133
const arr = new Array();
141134
arr.push(f.toString());

wasm/src/types/integer.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,18 @@ macro_rules! impl_integer {
142142
Self(self.0.pow(&exponent.0))
143143
}
144144

145+
/// Negates the integer (e.g., 5 → -5).
146+
#[wasm_bindgen(js_name = "neg")]
147+
pub fn neg(&self) -> $name {
148+
Self(-self.0)
149+
}
150+
151+
/// Checks equality with another integer.
152+
#[wasm_bindgen(js_name = "equals")]
153+
pub fn equals(&self, other: &$name) -> bool {
154+
self.0 == other.0
155+
}
156+
145157
/// Remainder.
146158
#[wasm_bindgen(js_name = "rem")]
147159
pub fn rem(&self, other: &$name) -> $name {

0 commit comments

Comments
 (0)