169 похожих чатов

Hi. Is it safe to do arithmetic operations with different

uint? For example uint256 with uint16 or better to use one type?

9 ответов

30 просмотров

Unsigned integers (uint) are similar to integers, but they can only store positive values. Like integers, unsigned integers can be declared with a number of bits, such as uint8, uint16, uint32, uint64, and so on, up to uint256.

It depends what you're trying to do and what you expect to be the maximum uint in your arithmetic's. Using smaller uint's are more gas efficient.

Bogdan- Автор вопроса
SPooCK
It depends what you're trying to do and what you e...

for example this function function calculate(uint256 a, uint16 b) public view returns (uint256 memory) { uint256 result = a * b - a; return result; } is it safe?

Bogdan
for example this function function calculate(uint...

That would depend on what you're calculating there, if its Token amounts, NO its not. For Tokens minimum use uint128.

Bogdan- Автор вопроса

What are you multiplying the Token amount with? I suppose this is a percentage? And always close your logic in brackets for any case uint256 result = (a * b) - a;

Bogdan- Автор вопроса
SPooCK
What are you multiplying the Token amount with? I ...

yes, it's like the loan calculator. User enters the amount of tokens and the percentage

Bogdan
yes, it's like the loan calculator. User enters th...

Then its fine, if you dont expect "b" to ever go over 65,535, should work as good and even a soft stopper for anyone adding anything above.

Bogdan- Автор вопроса

Похожие вопросы

Обсуждают сегодня

а зачем этот вопрос для удаления из чата?
Mёdkinson Medvezhkin
63
Эх кто-то пришел и весь праздник испортил :( You need complex FBX scene importing setup to change things on import? good luck with that. You need navigation and pathfinding? g...
Serg Gini
5
Всем привет! Подскажите. Я написал приложение на Delphi 10.2 Tokyo под Windows 10. И передо мной стал вопрос о том чтобы сделать это приложение кроссплатформенным (под Linux и...
Дмитрий Завгородний
24
Какого хера? /Sources/App/Modules/User/Models/UserLinkApple.swift:21:20: warning: stored property '_id' of 'Sendable'-conforming class 'UserLinkApple' is mutable @ID(...
Alexander Sherbakov
12
У тебя в конфиге нигде нет deny all; или вообще любого deny?
Alexander Sherbakov
10
Почему стало ломаться на D11? "739002.86400000' is not a valid timestamp" function IncDateTime(aStamp:TTimeStamp;aKind:TTriggerKind;aInterval:Integer):TDateTime; //aStamp = 2...
Катерина Свиридова
8
Привет всем. Подскажите где можно посмотреть, какая версия электрон, поддерживает версии windows? Некий changelog. Мне бы желательно, поддержку 7,8,10... latest, как понимаю и...
Anonym Squad
21
Портфолио: Зовут меня Александр, мне 36 лет. Город Пушкино. Общий рабочий стаж: ~14 лет Уровень квалификации: Senior Full-stack developer Где прочесть мой код? https://github....
Magic
10
думаешь я не смогу также сделать? мне это просто не удобно
int 💳 𝙖𝙞𝙧 𝙗𝙞𝙜 𝙗𝙤𝙗 🔫 check bio / spam block / AFK / nohello.com / GMT+3
9
Ребят, чет я уже не догоняю... Крч в коде на асм там происходит нечто вроде a+число (a+1, a+2 и т.д.). Но почему строка lea ecx, [edx+1] работает как a+1?? В edx берется адрес...
Alan 🔝 Бэброу
4
Карта сайта