3

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.

Hudson Jameson
  • 4,621
  • 2
  • 22
  • 34

1 Answers1

3

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.

Loi.Luu
  • 2,103
  • 3
  • 13
  • 16