[haiku-development] Re: DeskCalc Improvements (was need strtold() function)

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Fri, 22 Jan 2010 19:24:47 +0100

On 2010-01-22 at 17:58:13 [+0100], John Scipione <jscipione@xxxxxxxxx> 
wrote:
> I figured out how to get the DeskCalc application to clip the result
> based on the size of the window pretty well now by figuring out the
> current font size and the window width and doing a bit of math.
> However, while this is a nicety my testing has revealed what I believe
> to be a bug. If you type 1E6 in to DeskCalc you'll get the correct
> result, 1000000. But if you type 1E+6 you'll get 7 as a result.
> DeskCalc ignores the E when it sees a + sign and thinks that some sort
> of addition is going on. No amount of parenthesis seem to be able to
> correct this. What is worse is that 1E-6 will result in -5 and not
> 0.00001 as it should. This problem was revealed because I sometime
> output the result in scientific notation and the MAPM library uses the
> 999E+99 syntax to display its results. The code to parse the
> expression entered from DeskCalc can be found in
> src/kits/shared/ExpressionParser.cpp. I have modified the _ParseSum()
> function to try and skip over the offending + and - token that follows
> the E but have had no success. Here is some sample code to look at.
[...]
> Can somebody look at the ExpressionParser.cpp code and see if they can
> give me some advice on what the best way to fix this parse bug is?

Since the whole number should be a single token, the problem is not in the 
parser, but in the tokenizer. Have a look at Tokenizer::NextToken(). 
There's already an attempt to handle scientific notation, but it doesn't 
seem to be correct.

CU, Ingo

Other related posts: