About ~uint256(0)

uint256 private constant MAX = ~uint256(0);
uint256 private constant _tTotal = 10 * 10**6 * 10**9;
uint256 private _rTotal = (MAX - (MAX % _tTotal));

What is the value of the MAX and _rTotal constants?
I couldn’t understand the MAX constant :frowning:

1 Like

Hi, means bitwise negation, so ~uint256(0) = 2**256-1, that is the max value in the type of uint256, and these are just some mathematical calculations, if you do not know, you can deploy the contract to see the final result:

uint256 public constant MAX = ~uint256(0);
uint256 public constant _tTotal = 10 * 10**6 * 10**9;
uint256 public _rTotal = (MAX - (MAX % _tTotal));

So the results are:

MAX = 115792089237316195423570985008687907853269984665640564039457584007913129639935
_tTotal = 10000000000000000
_rTotal = 115792089237316195423570985008687907853269984665640564039457580000000000000000

Where can I check the value of these constants while writing the contract?

for example:


What should I do if I want to see the result as defined as?

I am still in the first hours so I am very inexperienced :slight_smile:
what should be in a developer’s bag? Which tools and what are their functions?

1 Like

You can use console.log, https://medium.com/nomic-labs-blog/better-solidity-debugging-console-log-is-finally-here-fc66c54f2c4a, but now, this plugin renamed hardhat

1 Like

thank you so much. Let’s see how the result will be :slight_smile:

1 Like

3 posts were merged into an existing topic: What does Reflect.Finance code do: _rTotal = (MAX - (MAX % totalSupplyOfToken));

Any special reason why it’s calculated like this:
uint256 public constant _tTotal = 10 * 10**6 * 10**9;

And not like this:
10*24 ?

Maybe token decimals is 9, so use 10**9
initial amount is 10 Million, so use 10 * 10**6

Yeah, of course, you can use 10**24, it depends on you, but you should know what does this number mean exactly.

1 Like

I figured it out as well and I think I’ll stick with the more common way (10**9 * 10**6 * 10**9)

I seem to forget one 10**9 from my question as well (I’m currently studying a contract (EverRise) with 9 decimals and 1000000000 * 10**6 * 10**9 digits :sweat_smile: :man_facepalming:

I didn’t first realize that the 10**9 was about the decimals, but now it makes more sense.
Thanks for that tip!

1 Like