Solidity does not natively support infinity, so how would I represent infinity as a variable in Solidity? For example, if I wanted to write an implementation of Dijkstra's algorithm in Solidity it would need infinity.

  • Writing an infinity algorithm in solidity would be waste of time since you cant execute it. The best thing is to keep an eye on the balance and gas price and execute as necessary. If its for educational purposes, yes we can work something out in a private-chain.
    – niksmac
    Commented Mar 31, 2016 at 2:18
  • This is for educational purposes so this would not necessarily be on the main chain, but in a test-rpc environment or private chain. Commented Mar 31, 2016 at 2:43
  • Related: Max/min values of standard data types Commented Apr 1, 2021 at 10:01

1 Answer 1


One possible way is to set a MAX_VALUE in your code, which is practically large enough so it will never be reached. Or if all the distances are positive, you can use a negative number to represent an infinite value.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.