Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!ecngs!feeder2.ecngs.de!newsfeeder.ewetel.de!82.197.223.103.MISMATCH!feeder3.cambriumusenet.nl!feeder1.cambriumusenet.nl!feed.tweaknews.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <1416612.AFRqVoOGUt@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sat, 28 Apr 2012 13:04:24 +0200 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. <6507721.320.1335573024044.JavaMail.geo-discussion-forums@ynen8> Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 45 NNTP-Posting-Date: 28 Apr 2012 13:04:24 CEST NNTP-Posting-Host: a724f2e0.newsspool1.arcor-online.net X-Trace: DXC=8?TRlgclN\2LNKYb?b>076ic==]BZ:af>4Fo<]lROoR1nkgeX?EC@@0E^]7Dg`Z:Q:DZm8W4\YJNK0fQ>EOE\[m`;dgZSHIf\_;2 X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:13661 Stefan Weiss wrote: > On 2012-04-28 02:30, Michael Haufe (TNO) wrote: >> Simple enough for the mathematically inclined: >> >> function f(n){ return (n-(n%3))/3 } > > Ah yes, I forgot to add that one. However, that approach requires three floating-point operations (and one call of a user-defined function), whereas Math.floor(n / 3) only requires two (and one property access and one built-in function call). ISTM that therefore the cost and potential rounding error is greater with the former than with the latter, and that the latter should be preferred, at least for n >= 0. > […] > In JS, -5.5 % 3 is -2.5 ... You mean _in conforming implementations of ECMAScript_, of course. > In PHP, -5.5 % 3 is -2 ... > > In Python, -5.5 % 3 is 0.5 ... > > In Perl, -5.5 % 3 is 1 ... > (unless you "use integer", then it depends on the compiler) > > In C, -5.5 % 3 doesn't work at all (int only)... > (but fmod(-5.5, 3) returns -2.5) > (oh, and the behavior with negative numbers is > "implementation defined") Fascinating. PointedEars -- Prototype.js was written by people who don't know javascript for people who don't know javascript. People who don't know javascript are not the best source of advice on designing systems that use javascript. -- Richard Cornford, cljs,