Complex math calculation - General - Algorand
Complex math calculation
post by hungpq on Mar 21, 2022
AVM currently now support almost like other blockchain platform so there are more and more defi app to follow in the upcoming days.
So i want to ask how to perform complex pow math (with large number). i can see bytesadd, … but cant seem to find with pow calculation. if can, can you give me example of how to use them in PyTeal (what happened if overflow, etc…)
Thanks for reading.
post by Ben on Mar 21, 2022
Hi Hung,
I think the exp opcode might be what you’re looking for in the case of pow
Overflow would result in termination of the program and failure of the transaction.
post by hungpq on Mar 21, 2022
thanks for your answer
what is the different between exp and expw? it would be great if you can give some example.
and also i want to know how to do bit shift in teal? for example i want to express the value 4 and 7 in a single bytes, each value can have 64 bit length (ex: 00000000000000040000000000000007)
post by fabrice on Mar 21, 2022
The output of expw is 128 bits (=16 bytes).
The difference between exp and expw is the same as the difference between mul and mulw.
I guess 00000000000000040000000000000007 is in hexadecimal. If yes, this is 128 bits = 16 bytes.
So this cannot be represented by an uint64. If this was the output of expw, one of the output of expw would be 4, the other 7.
post by hungpq on Mar 21, 2022
Ok i’ll tell you more detail
I’m writing Log in contract. Are there any best practice for this? As i know log only accept log for 1 bytes. So i have to put all parameters in a single bytes. Thats why i asked this question.
For example with the question i ask, i want to log the value 00000000000000040000000000000007 To express the 2 value 4 and 7. So the log-reader can understand it is 2 params, each 64 bit.
So i think the question here should be how to express 2 uint64 in a single bytes?
post by hungpq on Mar 22, 2022
And speaking of log, i read this in the docs (Opcodes - Algorand Developer Portal) that have the limit MaxLogCalls params.
Could you tell me more about this limit, is that max number of log in a transaction. or an application only can log MaxLogCalls time, then it can not emit log anymore?
post by Ben on Mar 22, 2022
The limits for log are detailed here:
Up to 32 times, up to 1024 bytes
post by hungpq on Mar 22, 2022
Thanks Ben for your answer. it helps me a lot
what i want to ask here is Up to 32 times, up to 1024 bytes in a single transaction/1 application call. or it is a limit forever in an application. it can log up to 32 times for entire life cycle of its. no matter in how many transactions call to its application?
post by Ben on Mar 22, 2022
Its a per application call limit.
post by FrankS on Mar 22, 2022
Itob and concat. If by bytesadd you mean the bigint byte array numbers then exp will need b× and a loop.