Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!newsfeed1.swip.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <10475868.RPHzNtd8jb@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Fri, 13 Sep 2013 02:27:08 +0200 User-Agent: KNode/4.10.5 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+&. <3251928.WeJvBNZfad@PointedEars.de> MIME-Version: 1.0 Lines: 46 NNTP-Posting-Date: 13 Sep 2013 02:27:11 CEST NNTP-Posting-Host: 061751c7.newsspool4.arcor-online.net X-Trace: DXC=DkX43I8C^8bPXlQ;h]GTMd4IUK Thomas 'PointedEars' Lahn posted: >> Stefan Weiss wrote: >>> […] I just calculated the [prime] numbers up to 200M. There are 11078937 >>> of them, which would require ~44MB of storage (using 4 bytes to store a >>> number). If I went the full 2B, the necessary disk storage would still >>> be less than half a gig. […] >> >> The relevant ECMAScript implementations support only one numeric data >> type, Number, which is an implementation of IEEE-754 double-precision >> floating-point values. Each such value requires 64 bits of storage (1 >> sign bit, 11 exponent bits, and 52 mantissa bits), or _8_ bytes whereas >> each byte consists of 8 bits. > > But perhaps it has not occurred to you that, /in extremis/, one can > store nearly 64 bits in an ECMAScript IEEE-754 Double. I believe I have just said that. > IIRC, of the 2^64 bit patterns in an 8 byte Double, two represent the > infinities, and about 2^53 represent NaN, which ECMAScript cannot > "resolve". True, but: > One can very easily store 32 bits in a Number, using the integer values > 0 to 2^32-1. I do not see how that could reduce the memory footprint without some form of (potentially expensive) compression. The 0-bits of the IEEE-754 value must *also* be stored in memory. Another problem is the limited number of elements in an Array (2³²−2). This means that there comes a point where it is no longer possible to simply push to an array like Stefan did, and you have to use, e. g., an Object instance whose properties you set (you could also use an Array instance, but there is no obvious advantage, and a clear disadvantage: potentially an even greater memory footprint), as Ben suggested. IOW, Ben’s approach scales better than both Stefan‘s and the OP’s. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.