Strategies for simplifying math expressions

前端 未结 6 1722
醉梦人生
醉梦人生 2020-11-27 10:28

I have a well-formed tree that represents a mathematical expression. For example, given the string: \"1+2-3*4/5\", this gets parsed into:

subtr         


        
6条回答
  •  猫巷女王i
    2020-11-27 11:09

    You actually can't in general do this because, although they are the same mathematically, the may not be the same in computer arithmetic. For instance, -MAX_INT is undefined, so --%a =/= %a. Similarly for floats, you have to deal with NaN and Inf appropriately.

提交回复
热议问题