# Infinite value for algorithm

**URL:** <https://discourse.processing.org/t/infinite-value-for-algorithm/23661>\
**Category:** Processing.py\
**Created:** [September 3, 2020, 7:11pm UTC](https://discourse.processing.org/t/infinite-value-for-algorithm/23661 "2020-09-03T19:11:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arcadeperfect](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@arcadeperfect](https://discourse.processing.org/u/arcadeperfect)\
**Post date:** [September 3, 2020, 7:11pm UTC](https://discourse.processing.org/t/infinite-value-for-algorithm/23661/1 "2020-09-03T19:11:56Z")

</div>

Hi  
Is there an equivalent of float(‘inf’) in Python to use in min operations to find the smallest value in a loop?

Thanks

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [September 3, 2020, 8:23pm UTC](https://discourse.processing.org/t/infinite-value-for-algorithm/23661/2 "2020-09-03T20:23:42Z")

</div>

I’m not sure if it is a Python 2.X thing but, you can use `float('Infinity')`.

But I would use just a big number like `1e100`

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/6976051822740173cab3336a2fa2ede5ce291808.png)

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/284a32091cc864e1432d62e9452b9af019e6bc92.png)

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [September 3, 2020, 9:21pm UTC](https://discourse.processing.org/t/infinite-value-for-algorithm/23661/3 "2020-09-03T21:21:22Z")

</div>

The answer is to set the minimum value to the first element in the array/list then check it against all the other elements, updating the minimum value if we find a smaller value. Can use similar approach for maximum values.  
This algorithm has the advantage in that it makes no assumptions about the values in the array/list so will work in all cases provided all the elements are the same type and are comparable.
