Prev: Firefox cache issue
Next: FAQ Topic - How do I format a Number as a String with exactly 2 decimal places? (2010-05-27)
From: Ry Nohryb on 28 May 2010 08:53 On May 28, 2:34 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de> wrote: > (...) > As for your misusing arguments as local variables and the resulting > unreadable You may find it so, not me. > unmaintainable you opinion > and insecure code each and every parameter is properly initialized before use. > , that has been discussed ad > nauseam. Will you ever learn? yes, and faster than you, it seems to me. > (...) -- Jorge.
From: Ry Nohryb on 28 May 2010 08:57 On May 28, 2:34 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de> wrote: > (...) > So you are essentially saying that you managed to produce code garbage, > as usual? LOL^2 > And stop calling me Pointy, Georgina. LOL, Georgina ? No, leave that or I'll call you MissPointy. -- Jorge.
From: Thomas 'PointedEars' Lahn on 28 May 2010 08:57 Ry Nohryb wrote: > Thomas 'PointedEars' Lahn wrote: >> Ry Nohryb wrote: >> > [...] >> > pointyParseFloat((-Math.PI).toString(16), 16) >> > --> -2.858407346410207 >> >> Yes, good catch; we need to consider the sign with addition, e.g.: >> >> var s = (-Math.PI).toString(16); >> var i = parseInt(s, 16); >> var f = (s.match(/\.([\da-f]+)/i) || [, "0"])[1]; >> var n = i + (i < 0 ? -1 : 1) * parseInt(f, 16) / Math.pow(16, f.length); >> (...) > > Better, but still not there: > > function pointyParseFloat (s, base) { > var i = parseInt(s, base); > var f = (s.match(/\.([\da-f]+)/i) || [, "0"])[1]; ^^^^^ > return i + (i < 0 ? -1 : 1) * parseInt(f, base) / Math.pow(base, > f.length); > } > > pointyParseFloat((-Math.PI).toString(33), 33) ^^ ^^ > --> -3.121212121212121 You have not considered that this example was suited to *hexadecimal* representations. parseFloat((-Math.PI).toString(33), 33) and jsx.string.parseFloat((-Math.PI).toString(33), 33) as posted return -3.141592653589793 (approx. -Math.PI), as expected. 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, <f806at$ail$1$8300dec7(a)news.demon.co.uk>
From: Thomas 'PointedEars' Lahn on 28 May 2010 08:59 Ry Nohryb wrote: > Thomas 'PointedEars' Lahn wrote: >> var parseFloat /*= jsx.string.parseFloat*/ = (function () { >> var origPF = parseFloat; >> >> return function (s, iBase) { >> if (!iBase || iBase == 10) >> { >> return origPF(s); >> } >> >> var >> i = (s.indexOf(".") != 0 ? parseInt(s, iBase) : 0), >> chars = (iBase < 10 >> ? "0-" + String.fromCharCode(47 + iBase) >> : "\\d" >> + (iBase > 10 >> ? "a" >> + (iBase > 11 >> ? "-" + String.fromCharCode(86 + iBase) >> : "") >> : "")), >> f = (s.match(new RegExp("\\.([" + chars + "]+)", "i")) || [, "0"])[1], >> >> return i + (i < 0 ? -1 : 1) >> * parseInt(f, iBase) / Math.pow(iBase, f.length); >> }; >> >> }()); > > > parseFloat(Math.PI.toString(33), 33) > --> NaN I cannot confirm this. Where have you tested it? 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, <f806at$ail$1$8300dec7(a)news.demon.co.uk>
From: Thomas 'PointedEars' Lahn on 28 May 2010 09:02
Ry Nohryb wrote: > Thomas 'PointedEars' Lahn wrote: >> As for your misusing arguments as local variables and the resulting >> unreadable > > You may find it so, not me. > >> unmaintainable > > you opinion Your code style is being frowned upon by several knowledgable people here. >> and insecure code > > each and every parameter is properly initialized before use. Unless you happen to forget doing that, which is likely with that code style. PointedEars -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee |