Search code examples
androidmathpow

power expressed as a ** b on Android


I am converting an iOS app into Android.

On iOS, the app is using DDMathEvaluator to calculate the result of strings received from elsewhere. Now on Android, I can't find DDMathEvaluator and have used ExpressionBuilder instead.

It works fine, except for parsing powers. On iOS, I can do a ** b, but on Android this wont work, I need to do it with pow(a,b).

As I can't influence the strings I receive, I was wondering if there is anything available on Android that allows to evaluate a ** b ?


Solution

  • You can use a ^ b instead of a ** b, see Expression Builder's code for reference, it's one of the "builtin operators".

    To transition between both, you can use String.replace, which returns a copy of the input String.