Reputation: 627
I am trying to use the DDMathParser in my application, and am having difficulty in getting it to work with % symbol as percent, instead of modulo.
The wiki advises the following -
The % sign is usually interpreted as the modulo operator. However, DDMathParser.h defines a compile-time switch (DD_INTERPRET_PERCENT_SIGN_AS_MOD) that allows you to change it to be interpreted as a percentageI
I added this define in the DDMathParser.h , but it hasn't worked. expressions are still calculated as modulo, and this is not the result i would like.
Does anybody have any experience of this, and know specifically how to set this up?
Please advise
Upvotes: 0
Views: 161
Reputation: 143
I've been able to resolve this. First of all, you have to add this to your code, as mentioned before:
[[DDMathOperatorSet defaultOperatorSet] setInterpretsPercentSignAsModulo:NO];
Then however, you also need to fix a bug in the DDMathParser source code. I've been using the latest available ObjectiveC version of the source, dated Nov 10, 2015, from here: https://github.com/davedelong/DDMathParser/releases/tag/objc , and the bug is in the DDMathOperator.m
Where it says:
return OPERATOR(DDMathOperatorPercent, @[@"%"], BINARY, 0, LEFT);
change it to:
return OPERATOR(DDMathOperatorPercent, @[@"%"], UNARY, 0, LEFT);
That's it - percents calculate fine afterward.
Upvotes: 0
Reputation: 54
You can use the following
[[DDMathOperatorSet defaultOperatorSet] setInterpretsPercentSignAsModulo:NO];
Upvotes: 1