# Complex math calculation

**URL:** <https://forum.algorand.co/t/complex-math-calculation/6304>\
**Category:** General\
**Tags:** smart-contracts\
**Created:** [March 21, 2022, 6:50am UTC](https://forum.algorand.co/t/complex-math-calculation/6304 "2022-03-21T06:50:36Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![hungpq](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@hungpq](https://forum.algorand.co/u/hungpq)\
**Post date:** [March 21, 2022, 6:50am UTC](https://forum.algorand.co/t/complex-math-calculation/6304/1 "2022-03-21T06:50:36Z")

</div>

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 perfrom 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 happend if overflow, etc…)

Thanks for reading.

---

<div class="post-metadata">

**Author:** ![Ben](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.algorand.co/ben/32/1979_2.png) [@Ben](https://forum.algorand.co/u/Ben)\
**Post date:** [March 21, 2022, 11:09am UTC](https://forum.algorand.co/t/complex-math-calculation/6304/2 "2022-03-21T11:09:29Z")

</div>

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.

Ben

---

<div class="post-metadata">

**Author:** ![hungpq](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@hungpq](https://forum.algorand.co/u/hungpq)\
**Post date:** [March 21, 2022, 11:11am UTC](https://forum.algorand.co/t/complex-math-calculation/6304/3 "2022-03-21T11:11:42Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![fabrice](https://avatars.discourse-cdn.com/v4/letter/f/5fc32e/32.png) [@fabrice](https://forum.algorand.co/u/fabrice)\
**Post date:** [March 21, 2022, 9:06pm UTC](https://forum.algorand.co/t/complex-math-calculation/6304/4 "2022-03-21T21:06:21Z")

</div>

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`.

> [@hungpq](#):
>
> 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)

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.

---

<div class="post-metadata">

**Author:** ![hungpq](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@hungpq](https://forum.algorand.co/u/hungpq)\
**Post date:** [March 21, 2022, 11:50pm UTC](https://forum.algorand.co/t/complex-math-calculation/6304/5 "2022-03-21T23:50:15Z")

</div>

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 parametters 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?

---

<div class="post-metadata">

**Author:** ![hungpq](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@hungpq](https://forum.algorand.co/u/hungpq)\
**Post date:** [March 22, 2022, 7:06am UTC](https://forum.algorand.co/t/complex-math-calculation/6304/6 "2022-03-22T07:06:02Z")

</div>

And speaking of log, i read this in the docs ([Opcodes - Algorand Developer Portal](https://developer.algorand.org/docs/get-details/dapps/avm/teal/opcodes/#log)) 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?

---

<div class="post-metadata">

**Author:** ![Ben](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.algorand.co/ben/32/1979_2.png) [@Ben](https://forum.algorand.co/u/Ben)\
**Post date:** [March 22, 2022, 10:53am UTC](https://forum.algorand.co/t/complex-math-calculation/6304/7 "2022-03-22T10:53:30Z")

</div>

Hung,

The limits for log are detailed here:

> **[Algorand parameter tables - Algorand Developer Portal](https://developer.algorand.org/docs/get-details/parameter_tables/?from_query=parameters#smart-contract-constraints)**
>
> Algorand Developer Docs, SDKs, REST APIs, CLI tools, ecosystem projects, metrics dashboard and sample code, how-tos, and news from the Algorand developer community

Up to 32 times, up to 1024 bytes

---

<div class="post-metadata">

**Author:** ![hungpq](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@hungpq](https://forum.algorand.co/u/hungpq)\
**Post date:** [March 22, 2022, 11:09am UTC](https://forum.algorand.co/t/complex-math-calculation/6304/8 "2022-03-22T11:09:30Z")

</div>

Thanks Ben for your answer. it help 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?

---

<div class="post-metadata">

**Author:** ![Ben](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.algorand.co/ben/32/1979_2.png) [@Ben](https://forum.algorand.co/u/Ben)\
**Post date:** [March 22, 2022, 1:56pm UTC](https://forum.algorand.co/t/complex-math-calculation/6304/9 "2022-03-22T13:56:53Z")

</div>

Its a per application call limit.

Ben

---

<div class="post-metadata">

**Author:** ![FrankS](https://avatars.discourse-cdn.com/v4/letter/f/74df32/32.png) [@FrankS](https://forum.algorand.co/u/FrankS)\
**Post date:** [March 22, 2022, 9:20pm UTC](https://forum.algorand.co/t/complex-math-calculation/6304/10 "2022-03-22T21:20:00Z")

</div>

Itob and concat. If by bytesadd you mean the bigint byte array numbers then exp will need b× and a loop
