Document and test a non-obvious feature of mozilla::ExponentComponent

RESOLVED FIXED in mozilla27

Status

()

enhancement
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: sunfish, Assigned: sunfish)

Tracking

unspecified
mozilla27
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

Assignee

Description

6 years ago
Zero constants are often printed as having a zero exponent, but they are actually encoded with a negative exponent. This patch documents how ExponentComponent handles zero, and adds some tests.
Attachment #814573 - Flags: review?(jwalden+bmo)
Comment on attachment 814573 [details] [diff] [review]
test-exponent-component.patch

Review of attachment 814573 [details] [diff] [review]:
-----------------------------------------------------------------

::: mfbt/tests/TestFloatingPoint.cpp
@@ +109,5 @@
> +{
> +  MOZ_ASSERT(ExponentComponent(0.0) == -int_fast16_t(DoubleExponentBias));
> +  MOZ_ASSERT(ExponentComponent(-0.0) == -int_fast16_t(DoubleExponentBias));
> +  MOZ_ASSERT(ExponentComponent(1.0) == 0);
> +  MOZ_ASSERT(ExponentComponent(2.0) == 1);

Let's add in a few fractionals and non-powers-of-two:

  MOZ_ASSERT(ExponentComponent(0.5) == -1);
  MOZ_ASSERT(ExponentComponent(0.125) == -3);
  MOZ_ASSERT(ExponentComponent(1.5) == 0);
  MOZ_ASSERT(ExponentComponent(7) == 2);
Attachment #814573 - Flags: review?(jwalden+bmo) → review+
Assignee

Comment 2

6 years ago
(In reply to Jeff Walden [:Waldo] (remove +bmo to email) from comment #1)
> Let's add in a few fractionals and non-powers-of-two:
> 
>   MOZ_ASSERT(ExponentComponent(0.5) == -1);
>   MOZ_ASSERT(ExponentComponent(0.125) == -3);
>   MOZ_ASSERT(ExponentComponent(1.5) == 0);
>   MOZ_ASSERT(ExponentComponent(7) == 2);

Done. https://hg.mozilla.org/integration/mozilla-inbound/rev/43a3626b2552
https://hg.mozilla.org/mozilla-central/rev/43a3626b2552
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla27
You need to log in before you can comment on or make changes to this bug.