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


Groups > comp.lang.javascript > #13751

Re: Javascript Math problem

From Dr J R Stockton <reply1218@merlyn.demon.co.uk.not.invalid>
Newsgroups comp.lang.javascript
Subject Re: Javascript Math problem
Date 2012-05-01 19:48 +0100
Organization Home
Message-ID <zQDjNiFVADoPFwxq@invalid.uk.co.demon.merlyn.invalid> (permalink)
References (1 earlier) <6507721.320.1335573024044.JavaMail.geo-discussion-forums@ynen8> <jnfivf$gj5$1@news.albasani.net> <1416612.AFRqVoOGUt@PointedEars.de> <jnhfar$7la$1@news.albasani.net> <67b160c3-9bd2-4872-9601-3125fff1c852@r13g2000vbg.googlegroups.com>

Show all headers | View raw


In comp.lang.javascript message <67b160c3-9bd2-4872-9601-3125fff1c852@r1
3g2000vbg.googlegroups.com>, Mon, 30 Apr 2012 06:19:50, Scott Sauyet
<scott.sauyet@gmail.com> posted:

>
>But there was a major discrepancy between `Math.floor(5 / 3)` and `(5
>- (5 % 3)) / 3`.  In Android 2.3.4, Math.floor was substantially
>slower than the bitwise operators, which were substantially slower
>than modulus-subtract-divide.  In Chrome 19.0.1077, Math.floor was
>slightly faster than the bitwise operators, and a bit slower than
>modulus-subtract-dived.  In Firefox 10, Math.floor was slightly slower
>than most of the bitwise operators, but more than twice as fast as
>modulus-subtract-divide.  And in IE 8.0.3, Math.floor was quite a bit
>slower than modulus-subtract-divide, which was slightly slower than
>the bitwise operators.  Of course the raw numbers for each browser was
>significantly different.

For simple cases like that, a browser might optimise out the formal call
to the actual function floor, in favour of working out the result at
compile time.  Then, the speed tests would be misleading.

Such a browser might (or might not) be deluded by executing, say,
Math["flo"+"or"] = Math.random before the call-under-test.  Certainly,
in MSIE 8, Firefox 12.0, Opera 11.62, Safari 5.1.5, Chrome 18.0,
Math.floor is not readonly :

        X = Math.floor(3.77)
        Math.floor = function () { return 2.96 }
        Y = Math.floor(3.77)
        Z = [X, Y]                      // gets [3,2.96]


-- 
 (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk  Turnpike 6.05  WinXP.
 Web  <http://www.merlyn.demon.co.uk/> - FAQ-type topics, acronyms, and links.
 Command-prompt MiniTrue is useful for viewing/searching/altering files. Free,
 DOS/Win/UNIX now 2.0.6; see <URL:http://www.merlyn.demon.co.uk/pc-links.htm>.

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


Thread

Javascript Math problem Tom <thart@vicon.net> - 2012-04-27 15:41 -0700
  Re: Javascript Math problem Stefan Weiss <krewecherl@gmail.com> - 2012-04-28 01:33 +0200
    Re: Javascript Math problem Tom <thart@vicon.net> - 2012-04-27 18:02 -0700
    Re: Javascript Math problem Dr J R Stockton <reply1217@merlyn.demon.co.uk.not.invalid> - 2012-04-29 21:07 +0100
      Re: Javascript Math problem "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-04-30 08:06 +0000
        Re: Javascript Math problem Tom <thart@vicon.net> - 2012-04-30 01:33 -0700
        Re: Javascript Math problem Dr J R Stockton <reply1218@merlyn.demon.co.uk.not.invalid> - 2012-05-01 19:30 +0100
  Re: Javascript Math problem "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-04-27 17:30 -0700
    Re: Javascript Math problem Tom <thart@vicon.net> - 2012-04-27 18:05 -0700
    Re: Javascript Math problem Stefan Weiss <krewecherl@gmail.com> - 2012-04-28 04:00 +0200
      Re: Javascript Math problem Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-28 13:04 +0200
        Re: Javascript Math problem Stefan Weiss <krewecherl@gmail.com> - 2012-04-28 21:10 +0200
          Re: Javascript Math problem Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-28 22:23 +0200
            Re: Javascript Math problem "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-04-28 23:39 +0300
            JS/Terminology (was: Javascript Math problem) Stefan Weiss <krewecherl@gmail.com> - 2012-04-29 05:59 +0200
              Re: JS/Terminology Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-29 16:15 +0200
                Re: JS/Terminology Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-29 16:20 +0200
                Re: JS/Terminology Puzzled <scratching.head@example.com> - 2012-05-07 16:22 -0400
                Re: JS/Terminology Gene Wirchenko <genew@ocis.net> - 2012-05-07 14:36 -0700
                Re: JS/Terminology "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-05-08 08:40 +0000
                Re: JS/Terminology Gene Wirchenko <genew@ocis.net> - 2012-05-08 09:29 -0700
            Re: Javascript Math problem John G Harris <john@nospam.demon.co.uk> - 2012-04-29 17:30 +0100
          Re: Javascript Math problem Scott Sauyet <scott.sauyet@gmail.com> - 2012-04-30 06:19 -0700
            Re: Javascript Math problem Dr J R Stockton <reply1218@merlyn.demon.co.uk.not.invalid> - 2012-05-01 19:48 +0100
              Re: Javascript Math problem Gene Wirchenko <genew@ocis.net> - 2012-05-01 19:30 -0700
      Re: Javascript Math problem "Mel Smith" <med_cutout_syntel@aol.com> - 2012-04-28 09:00 -0600
    Re: Javascript Math problem "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-04-28 09:02 +0000

csiph-web