Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: Convoluted logic trying to do bignumb Date: Wed, 15 Apr 2015 22:46:04 +0100 Organization: A noiseless patient Spider Lines: 45 Message-ID: <878udthxpf.fsf@bsb.me.uk> References: <57012849-2075-447d-8945-b52c8918a502@googlegroups.com> <8cd3a812-f346-4af0-97c7-62f02cd2264a@googlegroups.com> <79c50d33-33c7-4ff9-9a8d-29a2af3ee97b@googlegroups.com> <58540d8e-94a6-4e9b-914e-e18050dc2abd@googlegroups.com> <8419a2cd-49b3-46b1-984d-7cd3ac1fad72@googlegroups.com> <21469d11-c489-49f9-a4ea-ff3a56bab507@googlegroups.com> <31f09d6b-6684-4300-935e-316921f2dae3@googlegroups.com> <8909f1dc-882f-41cf-b335-fafc624b0ac3@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="5630"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+3s4k45/gsmLqUPAhn7HgFTLJcf/U1fow=" Cancel-Lock: sha1:hh88DfiAMgMgYC2HSdKe0RP0bjc= sha1:ZqNnteHjvrTvJOISqctfIlOGfRA= X-BSB-Auth: 1.0aeea561c6b779a18277.20150415224604BST.878udthxpf.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:27383 jonas.thornvall@gmail.com writes: > //CONVERT A DECIMAL NUMBER INTO ANYBASE > function newbase(decNumber,base){ As before, both the comment and name are misleading. The number stored in decNumber is not decimal any more than it is hexadecimal or octal. This confusion is repeated in your recent question about the base or operands. The number is independent of any base used to represent it, but values do have to be stored in computer programs and ECMAScript does this using a binary floating point representation that is very tightly specified. As a result, a comment like "convert a binary floating point number into any base" would not be wrong, thought it still draw attention to a matter that is of no consequence to the code. The function converts numbers, however they may be represented internally, into your own bignum representation. > var out =[]; > digits=1; > digmult=1; > while(digmult*base<=decNumber){ > digmult=digmult*base > digits++; > } I asked before why you do this rather than simply generate the digits is the more natural, least-significant first, order but you never explained. > digsave=digmult; > while(decNumber>0 || digits>=0){ > loop=1; > digit=0; > for (digit=0;digit<=base;digit++) { > if((digit+1)*digmult>decNumber)break; > } This is an exceptionally inefficient way to find the digit. Have you read up on any of the usual methods for doing what you are doing? -- Ben.