New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 658712 link

Starred by 3 users

Issue metadata

Status: Fixed
Owner:
Closed: Aug 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux , Windows , Mac
Pri: 2
Type: Bug



Sign in to add a comment

Error in number.toString conversion in (irregular) base

Reported by bcrie...@gmail.com, Oct 24 2016

Issue description

UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/53.0.2785.143 Chrome/53.0.2785.143 Safari/537.36

Steps to reproduce the problem:
1. open console
2. (0.19155912401454667).toString(36)
3. "0.6w9drpgd1345y0p63ovj10pb9"

What is the expected behavior?
"0.6w9drpgd134"

A numberstring in base 36 cannot be longer then a numberstring in base 10

Radix argument should be between 2-36 
`Uncaught RangeError: toString() radix argument must be between 2 and 36`

Also:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString

What went wrong?
Some fundamental arithmetic ;)

Try (0.19155912401454667).toString(11): "0.211a68745184085717213743862504511a687827188026678389aa0972798272a354303a4687548020541a076282927a62770387aa3632677a722aa43601a553973571a3296553520a41135261703237a47100908676739901063003153a62060660570859a6826458614aa720140a563036727688856608978016a690090738809a74947577993413333a1856a4a75556524158371816153326563111991972205714aa8542877a4550577055736766102703434697629499000305a9297953184a17a92822a319955a837025a34a005084095567257828a6420863a3705352433248307582907695857079169364885778783a736033aa517a3510208a1140097718535590354978151147342270931592a0a74005479203453945a31a999843a12059812601156247060268926980726273aa2065880599a1346a670a8579a6441196846865515934aa1309a187783a53a8a40a5a1794a89853890a1207443932436a0626245a6245724004295764a7a6073a255573958916a366a739442a63055687988498345632661643661979197144a87a202852568814038985664362a30345171586aa0764902698a1a7950509a2a44119a6369626560937535654796981810133745688aa4

Doesn't make sense to me. 

Did this work before? Yes Not sure

Chrome version: 53.0.2785.143  Channel: stable
OS Version: Ubunut 16.04
Flash Version: Shockwave Flash 11.2 r999

Quite sure this error wasn't in V8 a (while/some months/years) ago.
 

Comment 1 by e...@chromium.org, Oct 24 2016

Components: -Blink Infra>Client>V8 Blink>Bindings
Cc: rbasuvula@chromium.org
Labels: M-56 OS-Mac OS-Windows
Status: Untriaged (was: Unconfirmed)
Tested the issue on chrome Stable #54.0.2840.71, Canary 56.0.2900.0 in Ubuntu 14.04 and was able to reproduce the issue.

This is a Non-Regression issue since seeing this from M35 #35.0.1898.0, Making the status to Untriaged so that the issue would get addressed.

Note : Able to reproduce the issue in MAC 10.12 and Windows 10.0

Thank you.

Comment 3 by bcrie...@gmail.com, Oct 27 2016

On second thought, I'm not sure if this is really a bug.

For fractions, a numberstring in base 36 can be longer then a numberstring in base 10. 

Like 3 + 1/3 in base 3  = 10.1 while in base 10 it can only be estimated (3.33333)

It's probably a (not) rounding issue, a behavior that differs from Firefox and other JS engines. 
Components: -Blink>Bindings Blink>JavaScript
Cc: yangguo@chromium.org adamk@chromium.org dehrenberg@chromium.org
Components: -Blink>JavaScript -Infra>Client>V8 Blink>JavaScript>Language
Status: Available (was: Untriaged)
Is this something that works according to spec?
This is not a bug. 4/3 in base 3 is indeed 1.1. However, Javascript uses IEEE 754 floating point numbers, which are base 2. Storing 1/3 in base 2 will experience rounding errors.

The spec (20.1.3.6 Number.prototype.toString, step 7) says:

Return the String representation of this Number value using the radix specified by radixNumber. Letters a-z are used for digits with values 10 through 35. The precise algorithm is implementation-dependent, however the algorithm should be a generalization of that specified in 7.1.12.1.

So differing from Firefox does not surprise me.

Comment 7 by bcrie...@gmail.com, Nov 22 2016

Still the outcome of 0.19155912401454667).toString(11) does suggest a significance or precision that isn't there. (919 significant figures)

Isn't that a bug?

Cc: -dehrenberg@chromium.org littledan@chromium.org
This issue sounds very similar to  Issue 666376  . I don't think there's a spec violation (and one certainly should not read significance into IEEE float digits printed!), but it's possible that the Firefox results are subjectively "better" for users. Safari also outputs the shorter string.
Owner: adamk@chromium.org
Status: Fixed (was: Available)

Sign in to add a comment