From edc4b37ebb230d67401805d2c84ccd13012c2a3d Mon Sep 17 00:00:00 2001 From: Victor Magdesian <71725686+victorMagdesian@users.noreply.github.com> Date: Sun, 1 Dec 2024 23:34:05 -0300 Subject: [PATCH 1/2] Update felt252-type.adoc reference:https://cairo-by-example.com/examples/felt252/ --- .../pages/felt252-type.adoc | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/docs/reference/src/components/cairo/modules/language_constructs/pages/felt252-type.adoc b/docs/reference/src/components/cairo/modules/language_constructs/pages/felt252-type.adoc index 5f087b15262..d798550da5d 100644 --- a/docs/reference/src/components/cairo/modules/language_constructs/pages/felt252-type.adoc +++ b/docs/reference/src/components/cairo/modules/language_constructs/pages/felt252-type.adoc @@ -1,6 +1,33 @@ = Felt252 type -This section is a work in progress. -You are very welcome to contribute to this documentation by -link:https://github.com/starkware-libs/cairo/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22[submitting a pull request]. +Field elements have the property of intentionally "wrapping around" when their value exceeds the specified range, using modular arithmetic. + +== Code Example +The following example demonstrates how the maximum value of `felt252` behaves when adding `1`. + +[source, rust] +---- +fn main() { + // max value of felt252 + let x: felt252 = 3618502788666131213697322783095070105623107215331596699973092056135872020480; + let y: felt252 = 1; + assert(x + y == 0, 'P == 0 (mod P)'); +} +---- + +== Simplifying the Code +Since `felt252` is the default data type, there's no need to explicitly specify it in simple cases. Here’s the simplified version: + +[source, rust] +---- +fn main() { + // max value of felt252 + let x = 3618502788666131213697322783095070105623107215331596699973092056135872020480; + let y = 1; + assert(x + y == 0, 'P == 0 (mod P)'); +} +---- + +== Conclusion +The `felt252` data type uses modular arithmetic to ensure that all values remain within the allowed range. This makes it ideal for applications requiring reliable computation in finite fields. From 4e7d53d180991330bd989500e0c2bd549f4e7019 Mon Sep 17 00:00:00 2001 From: Victor Magdesian <71725686+victorMagdesian@users.noreply.github.com> Date: Mon, 2 Dec 2024 09:17:00 -0300 Subject: [PATCH 2/2] Update felt252-type.adoc - resolved lines wrap resolved lines wrap --- .../language_constructs/pages/felt252-type.adoc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/reference/src/components/cairo/modules/language_constructs/pages/felt252-type.adoc b/docs/reference/src/components/cairo/modules/language_constructs/pages/felt252-type.adoc index d798550da5d..0f1e50fea4b 100644 --- a/docs/reference/src/components/cairo/modules/language_constructs/pages/felt252-type.adoc +++ b/docs/reference/src/components/cairo/modules/language_constructs/pages/felt252-type.adoc @@ -1,7 +1,7 @@ = Felt252 type - -Field elements have the property of intentionally "wrapping around" when their value exceeds the specified range, using modular arithmetic. +Field elements have the property of intentionally "wrapping around" when their value exceeds the +specified range, using modular arithmetic. == Code Example The following example demonstrates how the maximum value of `felt252` behaves when adding `1`. @@ -17,7 +17,8 @@ fn main() { ---- == Simplifying the Code -Since `felt252` is the default data type, there's no need to explicitly specify it in simple cases. Here’s the simplified version: +Since `felt252` is the default data type, there's no need to explicitly specify it in simple cases. +Here’s the simplified version: [source, rust] ---- @@ -30,4 +31,5 @@ fn main() { ---- == Conclusion -The `felt252` data type uses modular arithmetic to ensure that all values remain within the allowed range. This makes it ideal for applications requiring reliable computation in finite fields. +The `felt252` data type uses modular arithmetic to ensure that all values remain within the allowed +range. This makes it ideal for applications requiring reliable computation in finite fields.