# Query on uint256 and int256

need to verify something, suppose i have this:

``````uint256 a =10;
uint256 b = 20;
uint256 c;
if (b > a) {
c = b-a;
(-c.mul(10))  // i want to multiply with -c intentionally
}
``````

this -c gonna give error, because uint256 can't be negetive. Can i do like this here?

``````uint256 a =10;
uint256 b = 20;
uint256 c;
if (b > a) {
c = b-a;
-int256(c);
(c.mul(10));    // Now will c become negetive here?
}
``````

Will -int256(c)` work??

And if i do `(0 - c).mul(10)`, will it work?

N.B: avoiding typecasting because i will have o change my code broadly.

• why are u using safe math?? its unnecessary with in solidity 8+ Commented Apr 27, 2023 at 1:22
• What should I use then ?Normal operators like `*` and `/`? Commented Apr 27, 2023 at 7:24
• Yes you can securely use normal operators with solidity 8+, it has it built in. The EVM will error before it under or overflows. Try it out in remix. If your trying to disable this feature you can use `unchecked { //code.. }` Commented May 2, 2023 at 23:33

## 1 Answer

cant you do it like this?

``````function test(uint256 a, uint256 b) public pure returns (int256 c) {
c = (b >= a) ? int256(b - a) * 10 : int256(a - b) * -10;
}
``````