I'm using NSExpression for doing some calculation but it retune incorrect value if the input value are large, say for example
eg,
NSString *equation = @"9999999999999 * 9999999999999"
NSExpression *expression = [NSExpression expressionWithFormat:equation]; //
id result = [expression expressionValueWithObject:nil context:nil]; //result is "-2537784290115403775"
If the equation would have been @"9 * 9" , then it return 18. Why does it returns incorrect value, if the input is bigger.
Please correct me, if i've misunderstood.
I think this is because this is because your calculation results in a number that cannot be stored in a
64 bit data type
. A 64 bit
data type signed int datatype can only store numbers upto -2^63
to 2^63-1
Your expression's result is obviously higher than the maximum limit.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.