Skip to content

Commit 7a64646

Browse files
update comments
1 parent 5473a0f commit 7a64646

File tree

1 file changed

+8
-9
lines changed
  • crates/starknet-types-core/src/felt

1 file changed

+8
-9
lines changed

crates/starknet-types-core/src/felt/qm31.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ impl QM31Felt {
3838
self.0
3939
}
4040

41-
/// Create a [QM31Felt] from the raw internal representation. Reduces four u64 coordinates and packs them
42-
/// into a single Felt252. STWO_PRIME fits in 36 bits, hence each coordinate can be represented
43-
/// by 36 bits and a QM31 element can be stored in the first 144 bits of a Felt252.
41+
/// Create a [QM31Felt] from the raw internal representation. Reduces four u64 coordinates so that the fit in 144 bits.
4442
pub fn from_raw(coordinates: [u64; 4]) -> QM31Felt {
4543
Self([
4644
coordinates[0] % STWO_PRIME,
@@ -50,6 +48,7 @@ impl QM31Felt {
5048
])
5149
}
5250

51+
/// Packs the [QM31Felt] coordinates into a Felt.
5352
pub fn pack_into_felt(&self) -> Felt {
5453
let coordinates = self.0;
5554

@@ -62,7 +61,7 @@ impl QM31Felt {
6261
Felt::from_bytes_le(&result_bytes)
6362
}
6463

65-
/// Computes the addition of two QM31 elements in reduced form.
64+
/// Computes the addition of two [QM31Felt] elements in reduced form.
6665
pub fn add(&self, rhs: &QM31Felt) -> QM31Felt {
6766
let coordinates1 = self.as_raw();
6867
let coordinates2 = rhs.as_raw();
@@ -75,7 +74,7 @@ impl QM31Felt {
7574
Self::from_raw(result_unreduced_coordinates)
7675
}
7776

78-
/// Computes the negative of a QM31 element in reduced form.
77+
/// Computes the negative of a [QM31Felt] element in reduced form.
7978
pub fn neg(&self) -> QM31Felt {
8079
let coordinates = self.as_raw();
8180
Self::from_raw([
@@ -86,7 +85,7 @@ impl QM31Felt {
8685
])
8786
}
8887

89-
/// Computes the subtraction of two QM31 elements in reduced form.
88+
/// Computes the subtraction of two [QM31Felt] elements in reduced form.
9089
pub fn sub(&self, rhs: &QM31Felt) -> QM31Felt {
9190
let coordinates1 = self.as_raw();
9291
let coordinates2 = rhs.as_raw();
@@ -99,7 +98,7 @@ impl QM31Felt {
9998
Self::from_raw(result_unreduced_coordinates)
10099
}
101100

102-
/// Computes the multiplication of two QM31 elements in reduced form.
101+
/// Computes the multiplication of two [QM31Felt] elements in reduced form.
103102
pub fn mul(&self, rhs: &QM31Felt) -> QM31Felt {
104103
let coordinates1_u64 = self.as_raw();
105104
let coordinates2_u64 = rhs.as_raw();
@@ -154,7 +153,7 @@ impl QM31Felt {
154153
u
155154
}
156155

157-
/// Computes the inverse of a QM31 element in reduced form.
156+
/// Computes the inverse of a [QM31Felt] element in reduced form.
158157
/// Returns an error if the operand is equal to zero.
159158
pub fn inverse(&self) -> Result<QM31Felt, QM31Error> {
160159
if *self == Self::ZERO {
@@ -195,7 +194,7 @@ impl QM31Felt {
195194
]))
196195
}
197196

198-
/// Computes the division of two QM31 elements in reduced form. Returns an error
197+
/// Computes the division of two [QM31Felt] elements in reduced form. Returns an error
199198
/// if the rhs value is equal to zero.
200199
pub fn div(&self, rhs: &QM31Felt) -> Result<QM31Felt, QM31Error> {
201200
let rhs_inv = rhs.inverse()?;

0 commit comments

Comments
 (0)