Skip to content

Commit

Permalink
chore: clarify to_radix docs examples (#7230)
Browse files Browse the repository at this point in the history
  • Loading branch information
iAmMichaelConnor authored Jan 29, 2025
1 parent 0242c17 commit 4d37fb0
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions noir_stdlib/src/field/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -384,19 +384,31 @@ mod tests {
#[test]
// docs:start:to_be_radix_example
fn test_to_be_radix() {
let field = 2;
// 259, in base 256, big endian, is [1, 3].
// i.e. 3 * 256^0 + 1 * 256^1
let field = 259;

// The radix (in this example, 256) must be a power of 2.
// The length of the returned byte array can be specified to be
// >= the amount of space needed.
let bytes: [u8; 8] = field.to_be_radix(256);
assert_eq(bytes, [0, 0, 0, 0, 0, 0, 0, 2]);
assert_eq(bytes, [0, 0, 0, 0, 0, 0, 1, 3]);
assert_eq(Field::from_be_bytes::<8>(bytes), field);
}
// docs:end:to_be_radix_example

#[test]
// docs:start:to_le_radix_example
fn test_to_le_radix() {
let field = 2;
// 259, in base 256, little endian, is [3, 1].
// i.e. 3 * 256^0 + 1 * 256^1
let field = 259;

// The radix (in this example, 256) must be a power of 2.
// The length of the returned byte array can be specified to be
// >= the amount of space needed.
let bytes: [u8; 8] = field.to_le_radix(256);
assert_eq(bytes, [2, 0, 0, 0, 0, 0, 0, 0]);
assert_eq(bytes, [3, 1, 0, 0, 0, 0, 0, 0]);
assert_eq(Field::from_le_bytes::<8>(bytes), field);
}
// docs:end:to_le_radix_example
Expand Down

2 comments on commit 4d37fb0

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 4d37fb0 Previous: 9f21824 Ratio
noir-lang_schnorr_ 1 s 0 s +∞

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 4d37fb0 Previous: 0242c17 Ratio
noir-lang_sparse_array_ 2 s 1 s 2
noir-lang_noir_check_shuffle_ 1 s 0 s +∞
noir-lang_ec_ 1 s 0 s +∞

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

Please sign in to comment.