NEWTON

Asked

4 months ago

13

views

0

If not, are there any workarounds?

ㅤ
*This question was originally posted on Triality*

- cairo-langcairo

0

You can also see on the cairo docs that a `felt`

is an integer in the range `-P/2 to P/2`

, where P is a very large (prime) number (currently it is a 252-bit number, which is a number with 76 decimal digits)

https://www.cairo-lang.org/docs/hello_cairo/intro.html#field-element

ㅤ
*This answer was originally posted on Triality*

answered

5 months ago

0

If you plug the following into a cairo script or the cairo playground: https://www.cairo-lang.org/playground/

You will get the following output:

Program output:

-1

-2

3

-7

Number of steps: 44

`%builtins output range_check`

`from starkware.cairo.common.serialize import serialize_word`

`from starkware.cairo.common.math_cmp import is_le`

``

``

`func main{output_ptr : felt*, range_check_ptr}():`

`let x = -1`

`let y = x + x`

`let z = y * y + x`

`let (a) = negative_nums(x)`

`serialize_word(x)`

`serialize_word(y)`

`serialize_word(z)`

`serialize_word(a)`

`return ()`

`end`

``

``

`#Show that negative numbers work fine with calculations`

`func negative_nums{range_check_ptr}(inp : felt) -> (res : felt):`

`let (isLe) = is_le(inp, 0)`

`if isLe == 1:`

`return (res=-5 + -2)`

`end`

`return (res=-4)`

`end`

``

Hopefully this shows that you can work with negative numbers just fine! Add any clarifications if there are any issues

ㅤ
*This answer was originally posted on Triality*

answered

5 months ago

0

a pointer with a hint, without doing a memory allocation

0

Does anyone have an example of a positional request to `starknet_addInvokeTransaction` on devnet that is working?

0

Is there a Cairo equivalent to Keccak256(abi.encode(parameters))?

0

What is Starknet.js?

3

How to write a function in Cairo Lang (StarkNet)?

0

Does Cairo work in python3.10 venv? I can’t install python 3.9

0

How to make recursive function in Cairo Lang?