Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #23746

Re: Expresson evaluation in javascript

Newsgroups comp.lang.javascript
Date 2014-03-30 09:21 -0700
References <62248b63-802b-4e9c-b3d3-d31c5003a24d@googlegroups.com> <533207f1$0$4217$9b4e6d93@newsspool2.arcor-online.net> <18bbc7cb-380c-438b-a5b6-285bd94fafd9@googlegroups.com> <afc859d9-8de9-4639-94ba-8eafd468af38@googlegroups.com>
Message-ID <7fbef56a-e8c7-40a4-9ec6-9f22bc4b306a@googlegroups.com> (permalink)
Subject Re: Expresson evaluation in javascript
From jonas.thornvall@gmail.com

Show all headers | View raw


Den söndagen den 30:e mars 2014 kl. 04:45:33 UTC+2 skrev Michael Haufe (TNO):
> On Wednesday, March 26, 2014 12:43:05 AM UTC-5, jonas.t...@gmail.com wrote:
> 
> 
> 
> > I was hoping for a math parser that could evaluate a mathematical expression in correct order, where you simply send the variable operands as a string broken down and calculated like 
> 
> > 
> 
> > strMath="x^y+uv-s"
> 
> > 
> 
> > evaluated=strMath.calc();
> 
> > 
> 
> > Surely someone must have implemented such a function already?
> 
> 
> 
> Implementing this for yourself should be relatively straightforward. One example of a parsing function as a starting point:
> 
> <http://rosettacode.org/wiki/Arithmetic_evaluation#JavaScript>
> 
> 
> 
> Here is a varied example of the given above:
> 
> 
> 
> function calc(str){
> 
>     return eval(str);
> 
> }
> 
> 
> 
> var x = 5, y = 2, u = 9, v = 4, s = 7;
> 
> 
> 
> var strMath="x*y+u/v-s";
> 
> 
> 
> var evaluated = calc(strMath);

Best tip given so far. I think i use this and maybe later implement my own when i need doing arithmetic in other bases.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Expresson evaluation in javascript jonas.thornvall@gmail.com - 2014-03-25 11:24 -0700
  Re: Expresson evaluation in javascript jonas.thornvall@gmail.com - 2014-03-25 11:43 -0700
    Re: Expresson evaluation in javascript jonas.thornvall@gmail.com - 2014-03-25 11:44 -0700
  Re: Expresson evaluation in javascript Danny <dann90038@gmail.com> - 2014-03-25 14:04 -0700
  Re: Expresson evaluation in javascript Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-03-25 18:40 -0300
  Re: Expresson evaluation in javascript Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-25 23:49 +0100
    Re: Expresson evaluation in javascript jonas.thornvall@gmail.com - 2014-03-25 22:43 -0700
      Re: Expresson evaluation in javascript jonas.thornvall@gmail.com - 2014-03-25 23:29 -0700
        Re: Expresson evaluation in javascript Jim T. <x@y.z> - 2014-03-28 11:48 -0500
          Re: Expresson evaluation in javascript jonas.thornvall@gmail.com - 2014-03-28 10:03 -0700
            Re: Expresson evaluation in javascript Jim T. <x@y.z> - 2014-03-28 13:12 -0500
            Re: Expresson evaluation in javascript "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-28 18:33 +0100
              Re: Expresson evaluation in javascript jonas.thornvall@gmail.com - 2014-03-28 10:50 -0700
                Re: Expresson evaluation in javascript jonas.thornvall@gmail.com - 2014-03-28 10:59 -0700
                Re: Expresson evaluation in javascript "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-28 20:38 +0100
                Re: Expresson evaluation in javascript "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-03-29 19:49 -0700
                Re: Expresson evaluation in javascript Ed Jay <edMbj@aes-intl.com> - 2014-03-29 10:53 -0700
      Re: Expresson evaluation in javascript "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-03-29 19:45 -0700
        Re: Expresson evaluation in javascript jonas.thornvall@gmail.com - 2014-03-30 09:21 -0700
        Re: Expresson evaluation in javascript jonas.thornvall@gmail.com - 2014-03-30 09:24 -0700
          Re: Expresson evaluation in javascript "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-30 21:19 +0200
          Re: Expresson evaluation in javascript "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-03-30 14:20 -0700
  Re: Expresson evaluation in javascript John Harris <niam@jghnorth.org.uk.invalid> - 2014-03-26 14:58 +0000
  Re: Expresson evaluation in javascript "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-03-29 19:33 -0700
  Re: Expresson evaluation in javascript Norman Peelman <npeelman@cfl.rr.com> - 2014-03-30 05:01 -0400

csiph-web