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.– niksmacCommented 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.– Hudson JamesonCommented Mar 31, 2016 at 2:43
-
Related: Max/min values of standard data types– Paul Razvan BergCommented Apr 1, 2021 at 10:01
Add a comment
|
1 Answer
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.