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.

  • 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 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 Jameson Mar 31 '16 at 2:43
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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