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.
Asked
Active
Viewed 883 times
3
-
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 Mar 31 '16 at 02: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 Jameson Mar 31 '16 at 02:43
-
Related: Max/min values of standard data types – Paul Razvan Berg Apr 01 '21 at 10:01
1 Answers
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