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:


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?


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


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


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 ?

1 Like

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.


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!


What does _rTotal stand for? So like for what is the variable used? What does the number it contains represent?

Read _rTotal as the reflected total. It does not mean anything. Think of it as a symbolic tool to make the reflection work.

So with reflected total, you mean something like the total after calculation of everything? So like the "real" amount of coins or datapackets or smth like that?

For example you can have 0.000000001 coins but if the coin has 9 decimals you then have one of the rTotal? Do i get this right?

tTotal is the true total and you can read it this way. rTotal is the reflected total for making this reflection mechanism work out. I believe the paragraphs in the picture below provides an intuitive explanation.

1 Like

Where is this piece from? Can I get the full script?