0

I have a function that requires a very strict type cast of either a 1 or a 2 for a uint. I got the part where the function will revert if the input is zero or over two. But I'm worried negative numbers can be passed. So my question...

Can solidity functions or the solidity language itself have negative numbers passed to it?

1

The answer to your question is Yes:

Solidity supports int types, which are treated arithmetically as signed values (i.e., can be positive, negative and zero).


The answer to your concern is No:

Since the type of your input is uint, it is treated arithmetically as an unsigned value, which can never be negative.


BTW, this is not unique to Solidity, but common in any typed-language.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.