Menu
  • HOME
  • TAGS

sin(pi()) does not return 0 in DDMathParser

objective-c,ddmathparser

The -description method on NSNumber does not accurately represent the underlying number: NSLog(@"%f", sin(M_PI)); // logs 0.000000 NSLog(@"%@", @(sin(M_PI))); // logs 1.224646799147353e-16 To work around this, you can pull out the -doubleValue of the NSNumber, and that should give you 0: NSLog(@"%f", @(sin(M_PI)).doubleValue); // logs 0.000000 ...

DDMathParser - Getting tokens

objective-c,ddmathparser

Ok. So, this appears to be the current way of getting tokens from a string: NSError *error = nil; DDMathOperatorSet *opSet = [DDMathOperatorSet defaultOperatorSet]; DDMathStringTokenizer *tokenizer = [[DDMathStringTokenizer alloc] initWithString:@"123+142-3/51815*(-5+2.0)" operatorSet:opSet error:&error]; NSArray *tokens = [tokenizer allObjects]; ...