- Joined
- Jan 2, 2020
- Messages
- 1,414
Is there a way to calculate constants at compiletime?
Code:
Import mojo2
Const LOG10:Float = 2.3025850929
' Const LOG10:Float = Log(10)
Function Main ()
New Game
Return 0
End
Class Game Extends App
Method OnCreate ()
Print digitCount(1234)
Return 0
End
End
Function Log10:Float(num:Float)
Return Log(num) / LOG10
End Function
Function digitCount:Float(num:Float)
If num = 0 Then Return 1
Return Floor(Log10(Abs(num))) + 1
End Function