Skip to content

Commit

Permalink
Editorial: make gb18030 math more clear
Browse files Browse the repository at this point in the history
Fixes #63.
  • Loading branch information
annevk committed Aug 4, 2016
1 parent 4bf904a commit b7ed173
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
19 changes: 9 additions & 10 deletions Overview.html
Expand Up @@ -9,7 +9,7 @@

<p><a class="logo" href="https://whatwg.org/"><img alt="WHATWG" height="100" src="https://resources.whatwg.org/logo-encoding.svg" width="100"></a></p>
<h1>Encoding</h1>
<h2 class="no-num no-toc" id="living-standard-—-last-updated-29-july-2016">Living Standard — Last Updated 29 July 2016</h2>
<h2 class="no-num no-toc" id="living-standard-—-last-updated-4-august-2016">Living Standard — Last Updated 4 August 2016</h2>

<dl>
<dt>Participate:
Expand Down Expand Up @@ -1732,7 +1732,9 @@ <h4 id="gb18030-decoder"><span class="secno">11.2.1 </span><dfn>gb18030 decoder<
<li><p>If <var>byte</var> is in the range 0x30 to 0x39, inclusive, set
<var>code point</var> to the
<a href="#index-gb18030-ranges-code-point">index gb18030 ranges code point</a> for
(((<a href="#gb18030-first">gb18030 first</a> − 0x81) × 10 + <a href="#gb18030-second">gb18030 second</a> − 0x30) × 126 + <a href="#gb18030-third">gb18030 third</a> − 0x81) × 10 + <var>byte</var> − 0x30.
((<a href="#gb18030-first">gb18030 first</a> − 0x81) × (10 × 126 × 10)) +
((<a href="#gb18030-second">gb18030 second</a> − 0x30) × (10 × 126)) +
((<a href="#gb18030-third">gb18030 third</a> − 0x81) × 10) + <var>byte</var> − 0x30.

<li><p>Let <var>buffer</var> be a byte sequence consisting of
<a href="#gb18030-second">gb18030 second</a>, <a href="#gb18030-third">gb18030 third</a>, and <var>byte</var>, in
Expand Down Expand Up @@ -1851,20 +1853,17 @@ <h4 id="gb18030-encoder"><span class="secno">11.2.2 </span><dfn>gb18030 encoder<
<li><p>Set <var>pointer</var> to the
<a href="#index-gb18030-ranges-pointer">index gb18030 ranges pointer</a> for <var>code point</var>.

<li><p>Let <var>byte1</var> be floor(<var>pointer</var> / 10 / 126 / 10).
<li><p>Let <var>byte1</var> be floor(<var>pointer</var> / (10 × 126 × 10)).

<li><p>Set <var>pointer</var> to
<var>pointer</var><var>byte1</var> × 10 × 126 × 10.
<li><p>Set <var>pointer</var> to <var>pointer</var> % (10 × 126 × 10).

<li><p>Let <var>byte2</var> be floor(<var>pointer</var> / 10 / 126).
<li><p>Let <var>byte2</var> be floor(<var>pointer</var> / (10 × 126)).

<li><p>Set <var>pointer</var> to
<var>pointer</var><var>byte2</var> × 10 × 126.
<li><p>Set <var>pointer</var> to <var>pointer</var> % (10 × 126).

<li><p>Let <var>byte3</var> be floor(<var>pointer</var> / 10).

<li><p>Let <var>byte4</var> be
<var>pointer</var><var>byte3</var> × 10.
<li><p>Let <var>byte4</var> be <var>pointer</var> % 10.

<li><p>Return four bytes whose values are <var>byte1</var> + 0x81,
<var>byte2</var> + 0x30, <var>byte3</var> + 0x81,
Expand Down
17 changes: 8 additions & 9 deletions Overview.src.html
Expand Up @@ -1649,7 +1649,9 @@ <h4><dfn>gb18030 decoder</dfn></h4>
<li><p>If <var>byte</var> is in the range 0x30 to 0x39, inclusive, set
<var>code point</var> to the
<span>index gb18030 ranges code point</span> for
(((<span>gb18030 first</span> &minus; 0x81) &times; 10 + <span>gb18030 second</span> &minus; 0x30) &times; 126 + <span>gb18030 third</span> &minus; 0x81) &times; 10 + <var>byte</var> &minus; 0x30.
((<span>gb18030 first</span> &minus; 0x81) &times; (10 &times; 126 &times; 10)) +
((<span>gb18030 second</span> &minus; 0x30) &times; (10 &times; 126)) +
((<span>gb18030 third</span> &minus; 0x81) &times; 10) + <var>byte</var> &minus; 0x30.

<li><p>Let <var>buffer</var> be a byte sequence consisting of
<span>gb18030 second</span>, <span>gb18030 third</span>, and <var>byte</var>, in
Expand Down Expand Up @@ -1768,20 +1770,17 @@ <h4><dfn>gb18030 encoder</dfn></h4>
<li><p>Set <var>pointer</var> to the
<span>index gb18030 ranges pointer</span> for <var>code point</var>.

<li><p>Let <var>byte1</var> be floor(<var>pointer</var> / 10 / 126 / 10).
<li><p>Let <var>byte1</var> be floor(<var>pointer</var> / (10 &times; 126 &times; 10)).

<li><p>Set <var>pointer</var> to
<var>pointer</var> &minus; <var>byte1</var> &times; 10 &times; 126 &times; 10.
<li><p>Set <var>pointer</var> to <var>pointer</var> % (10 &times; 126 &times; 10).

<li><p>Let <var>byte2</var> be floor(<var>pointer</var> / 10 / 126).
<li><p>Let <var>byte2</var> be floor(<var>pointer</var> / (10 &times; 126)).

<li><p>Set <var>pointer</var> to
<var>pointer</var> &minus; <var>byte2</var> &times; 10 &times; 126.
<li><p>Set <var>pointer</var> to <var>pointer</var> % (10 &times; 126).

<li><p>Let <var>byte3</var> be floor(<var>pointer</var> / 10).

<li><p>Let <var>byte4</var> be
<var>pointer</var> &minus; <var>byte3</var> &times; 10.
<li><p>Let <var>byte4</var> be <var>pointer</var> % 10.

<li><p>Return four bytes whose values are <var>byte1</var> + 0x81,
<var>byte2</var> + 0x30, <var>byte3</var> + 0x81,
Expand Down

0 comments on commit b7ed173

Please sign in to comment.