From 88269811512a734e40f1cf15ccbcb71f385e9319 Mon Sep 17 00:00:00 2001 From: Yoshi Huang Date: Wed, 11 Apr 2012 15:03:52 +0800 Subject: [PATCH 01/14] Bug 744306 - Part 1: response id collision in Akami & RIL v6. r=philikon --- dom/system/gonk/ril_worker.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dom/system/gonk/ril_worker.js b/dom/system/gonk/ril_worker.js index cc09c9724af6..a132ed0bed3d 100644 --- a/dom/system/gonk/ril_worker.js +++ b/dom/system/gonk/ril_worker.js @@ -2469,6 +2469,12 @@ RIL[UNSOLICITED_OEM_HOOK_RAW] = null; RIL[UNSOLICITED_RINGBACK_TONE] = null; RIL[UNSOLICITED_RESEND_INCALL_MUTE] = null; RIL[UNSOLICITED_RIL_CONNECTED] = function UNSOLICITED_RIL_CONNECTED(length) { + // Prevent response id collision between UNSOLICITED_RIL_CONNECTED and + // UNSOLICITED_VOICE_RADIO_TECH_CHANGED for Akami on gingerbread branch. + if (!length) { + return; + } + let version = Buf.readUint32List()[0]; RILQUIRKS_V5_LEGACY = (version < 5); if (DEBUG) { @@ -2477,7 +2483,6 @@ RIL[UNSOLICITED_RIL_CONNECTED] = function UNSOLICITED_RIL_CONNECTED(length) { } }; - /** * This object exposes the functionality to parse and serialize PDU strings * From b3126449e7860353e24cee0dc56cdc35964a73b5 Mon Sep 17 00:00:00 2001 From: Yoshi Huang Date: Wed, 11 Apr 2012 18:00:05 +0800 Subject: [PATCH 02/14] Bug 744306 - Part 2: enable RIL v6 on Akami. r=philikon --- dom/system/gonk/ril_worker.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/dom/system/gonk/ril_worker.js b/dom/system/gonk/ril_worker.js index a132ed0bed3d..9414500a9305 100644 --- a/dom/system/gonk/ril_worker.js +++ b/dom/system/gonk/ril_worker.js @@ -658,7 +658,14 @@ let RIL = { } RILQUIRKS_DATACALLSTATE_DOWN_IS_UP = true; } - + let ril_impl = libcutils.property_get("gsm.version.ril-impl"); + if (ril_impl == "Qualcomm RIL 1.0") { + if (DEBUG) { + debug("Detected Qualcomm RIL 1.0, " + + "disabling RILQUIRKS_V5_LEGACY to false"); + } + RILQUIRKS_V5_LEGACY = false; + } this.rilQuirksInitialized = true; }, @@ -2472,6 +2479,7 @@ RIL[UNSOLICITED_RIL_CONNECTED] = function UNSOLICITED_RIL_CONNECTED(length) { // Prevent response id collision between UNSOLICITED_RIL_CONNECTED and // UNSOLICITED_VOICE_RADIO_TECH_CHANGED for Akami on gingerbread branch. if (!length) { + this.initRILQuirks(); return; } From 1b16e8f217e593818bcdd69ef32a6fda411c389f Mon Sep 17 00:00:00 2001 From: Yoshi Huang Date: Mon, 2 Apr 2012 10:57:38 +0800 Subject: [PATCH 03/14] Bug 740300 - B2G RIL: improper behavior in RadioStateChange. r=philikon --- dom/system/gonk/ril_worker.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/dom/system/gonk/ril_worker.js b/dom/system/gonk/ril_worker.js index 9414500a9305..c7df1708a1f2 100644 --- a/dom/system/gonk/ril_worker.js +++ b/dom/system/gonk/ril_worker.js @@ -2361,12 +2361,6 @@ RIL[UNSOLICITED_RESPONSE_RADIO_STATE_CHANGED] = function UNSOLICITED_RESPONSE_RA radioState == RADIO_STATE_OFF) { return; } - if (RILQUIRKS_V5_LEGACY && - (radioState == RADIO_STATE_SIM_NOT_READY || - radioState == RADIO_STATE_RUIM_NOT_READY || - radioState == RADIO_STATE_NV_NOT_READY)) { - return; - } this.getICCStatus(); }; RIL[UNSOLICITED_RESPONSE_CALL_STATE_CHANGED] = function UNSOLICITED_RESPONSE_CALL_STATE_CHANGED() { From 1bb5c0078ec7a591cb5c9f05e5aa55ae4f45ba27 Mon Sep 17 00:00:00 2001 From: Paolo Amadini Date: Thu, 12 Apr 2012 12:27:14 +0200 Subject: [PATCH 04/14] Bug 737133 - getFaviconURLForPage and getFaviconDataForPage should invoke nsIFaviconDataCallback even if the favicon is not available. r=mak sr=gavin --HG-- extra : rebase_source : 70f0139a7b87b4a3f4de785a7c29f3f36e2055a9 --- browser/base/content/browser.js | 12 +-- .../preferences/aboutPermissions.js | 28 +++--- docshell/base/nsDocShell.cpp | 12 ++- .../components/places/AsyncFaviconHelpers.cpp | 94 ++++++++++--------- .../components/places/AsyncFaviconHelpers.h | 28 ++++-- .../components/places/mozIAsyncFavicons.idl | 27 ++++-- .../components/places/nsIFaviconService.idl | 31 +++--- .../places/tests/favicons/head_favicons.js | 18 +--- .../tests/favicons/test_expireAllFavicons.js | 3 +- .../places/tests/favicons/test_favicons.js | 2 +- .../favicons/test_getFaviconDataForPage.js | 57 +++++++++++ .../favicons/test_getFaviconURLForPage.js | 50 ++++++++++ .../places/tests/favicons/xpcshell.ini | 2 + .../tests/unit/test_preventive_maintenance.js | 5 +- widget/windows/JumpListBuilder.cpp | 8 +- 15 files changed, 253 insertions(+), 124 deletions(-) create mode 100644 toolkit/components/places/tests/favicons/test_getFaviconDataForPage.js create mode 100644 toolkit/components/places/tests/favicons/test_getFaviconURLForPage.js diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 71185f11b033..b47630d76526 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -3604,12 +3604,12 @@ function FillHistoryMenu(aParent) { item.setAttribute("index", j); if (j != index) { - function FHM_getFaviconURLCallback(aURI) { - let iconURL = PlacesUtils.favicons.getFaviconLinkForIcon(aURI).spec; - item.style.listStyleImage = "url(" + iconURL + ")"; - } - PlacesUtils.favicons.getFaviconURLForPage(entry.URI, - FHM_getFaviconURLCallback); + PlacesUtils.favicons.getFaviconURLForPage(entry.URI, function (aURI) { + if (aURI) { + let iconURL = PlacesUtils.favicons.getFaviconLinkForIcon(aURI).spec; + item.style.listStyleImage = "url(" + iconURL + ")"; + } + }); } if (j < index) { diff --git a/browser/components/preferences/aboutPermissions.js b/browser/components/preferences/aboutPermissions.js index fbe76b30374b..12d9d1665cf4 100644 --- a/browser/components/preferences/aboutPermissions.js +++ b/browser/components/preferences/aboutPermissions.js @@ -92,28 +92,28 @@ Site.prototype = { * A callback function that takes a favicon image URL as a parameter. */ getFavicon: function Site_getFavicon(aCallback) { - let callbackExecuted = false; - function faviconDataCallback(aURI, aDataLen, aData, aMimeType) { - // We don't need a second callback, so we can ignore it to avoid making - // a second database query for the favicon data. - if (callbackExecuted) { - return; - } + function invokeCallback(aFaviconURI) { try { // Use getFaviconLinkForIcon to get image data from the database instead // of using the favicon URI to fetch image data over the network. - aCallback(gFaviconService.getFaviconLinkForIcon(aURI).spec); - callbackExecuted = true; + aCallback(gFaviconService.getFaviconLinkForIcon(aFaviconURI).spec); } catch (e) { Cu.reportError("AboutPermissions: " + e); } } - // Try to find favicion for both URIs. Callback will only be called if a - // favicon URI is found. We'll ignore the second callback if it is called, - // so this means we'll always prefer the https favicon. - gFaviconService.getFaviconURLForPage(this.httpsURI, faviconDataCallback); - gFaviconService.getFaviconURLForPage(this.httpURI, faviconDataCallback); + // Try to find favicon for both URIs, but always prefer the https favicon. + gFaviconService.getFaviconURLForPage(this.httpsURI, function (aURI) { + if (aURI) { + invokeCallback(aURI); + } else { + gFaviconService.getFaviconURLForPage(this.httpURI, function (aURI) { + if (aURI) { + invokeCallback(aURI); + } + }); + } + }.bind(this)); }, /** diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index a5976c397bce..b8a0d43ec273 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -7894,8 +7894,7 @@ namespace { // Callback used by CopyFavicon to inform the favicon service that one URI -// (mNewURI) has the same favicon URI (OnFaviconDataAvailable's aFaviconURI) as -// another. +// (mNewURI) has the same favicon URI (OnComplete's aFaviconURI) as another. class nsCopyFaviconCallback : public nsIFaviconDataCallback { public: @@ -7907,9 +7906,14 @@ public: } NS_IMETHODIMP - OnFaviconDataAvailable(nsIURI *aFaviconURI, PRUint32 aDataLen, - const PRUint8 *aData, const nsACString &aMimeType) + OnComplete(nsIURI *aFaviconURI, PRUint32 aDataLen, + const PRUint8 *aData, const nsACString &aMimeType) { + // Continue only if there is an associated favicon. + if (!aFaviconURI) { + return NS_OK; + } + NS_ASSERTION(aDataLen == 0, "We weren't expecting the callback to deliver data."); nsCOMPtr favSvc = diff --git a/toolkit/components/places/AsyncFaviconHelpers.cpp b/toolkit/components/places/AsyncFaviconHelpers.cpp index 9ff2974b376e..8bd3d617024c 100644 --- a/toolkit/components/places/AsyncFaviconHelpers.cpp +++ b/toolkit/components/places/AsyncFaviconHelpers.cpp @@ -880,13 +880,9 @@ AsyncGetFaviconURLForPage::Run() nsCAutoString iconSpec; nsresult rv = FetchIconURL(mDB, mPageSpec, iconSpec); - NS_ENSURE_SUCCESS(rv, rv); + MOZ_ASSERT(NS_SUCCEEDED(rv)); - // No icon was found. - if (iconSpec.IsEmpty()) - return NS_OK; - - // Now notify our callback of the icon spec we retrieved. + // Now notify our callback of the icon spec we retrieved, even if empty. IconData iconData; iconData.spec.Assign(iconSpec); @@ -949,11 +945,7 @@ AsyncGetFaviconDataForPage::Run() nsCAutoString iconSpec; nsresult rv = FetchIconURL(mDB, mPageSpec, iconSpec); - NS_ENSURE_SUCCESS(rv, rv); - - if (!iconSpec.Length()) { - return NS_ERROR_NOT_AVAILABLE; - } + MOZ_ASSERT(NS_SUCCEEDED(rv)); IconData iconData; iconData.spec.Assign(iconSpec); @@ -961,8 +953,13 @@ AsyncGetFaviconDataForPage::Run() PageData pageData; pageData.spec.Assign(mPageSpec); - rv = FetchIconInfo(mDB, iconData); - NS_ENSURE_SUCCESS(rv, rv); + if (!iconSpec.IsEmpty()) { + rv = FetchIconInfo(mDB, iconData); + if (NS_FAILED(rv)) { + iconData.spec.Truncate(); + MOZ_NOT_REACHED("Fetching favicon information failed unexpectedly."); + } + } nsCOMPtr event = new NotifyIconObservers(iconData, pageData, mCallback); @@ -1091,45 +1088,54 @@ NotifyIconObservers::Run() "This should be called on the main thread"); nsCOMPtr iconURI; - nsresult rv = NS_NewURI(getter_AddRefs(iconURI), mIcon.spec); - NS_ENSURE_SUCCESS(rv, rv); - - // Notify observers only if something changed. - if (mIcon.status & ICON_STATUS_SAVED || - mIcon.status & ICON_STATUS_ASSOCIATED) { - nsCOMPtr pageURI; - rv = NS_NewURI(getter_AddRefs(pageURI), mPage.spec); - NS_ENSURE_SUCCESS(rv, rv); - - nsFaviconService* favicons = nsFaviconService::GetFaviconService(); - NS_ENSURE_STATE(favicons); - (void)favicons->SendFaviconNotifications(pageURI, iconURI, mPage.guid); - - // If the page is bookmarked and the bookmarked url is different from the - // updated one, start a new task to update its icon as well. - if (!mPage.bookmarkedSpec.IsEmpty() && - !mPage.bookmarkedSpec.Equals(mPage.spec)) { - // Create a new page struct to avoid polluting it with old data. - PageData bookmarkedPage; - bookmarkedPage.spec = mPage.bookmarkedSpec; - - // This will be silent, so be sure to not pass in the current callback. - nsCOMPtr nullCallback; - nsRefPtr event = - new AsyncAssociateIconToPage(mIcon, bookmarkedPage, nullCallback); - mDB->DispatchToAsyncThread(event); + if (!mIcon.spec.IsEmpty()) { + MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_NewURI(getter_AddRefs(iconURI), mIcon.spec))); + if (iconURI) + { + // Notify observers only if something changed. + if (mIcon.status & ICON_STATUS_SAVED || + mIcon.status & ICON_STATUS_ASSOCIATED) { + SendGlobalNotifications(iconURI); + } } } if (mCallback) { - (void)mCallback->OnFaviconDataAvailable(iconURI, - mIcon.data.Length(), - TO_INTBUFFER(mIcon.data), - mIcon.mimeType); + (void)mCallback->OnComplete(iconURI, mIcon.data.Length(), + TO_INTBUFFER(mIcon.data), mIcon.mimeType); } return NS_OK; } +void +NotifyIconObservers::SendGlobalNotifications(nsIURI* aIconURI) +{ + nsCOMPtr pageURI; + MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_NewURI(getter_AddRefs(pageURI), mPage.spec))); + if (pageURI) { + nsFaviconService* favicons = nsFaviconService::GetFaviconService(); + MOZ_ASSERT(favicons); + if (favicons) { + (void)favicons->SendFaviconNotifications(pageURI, aIconURI, mPage.guid); + } + } + + // If the page is bookmarked and the bookmarked url is different from the + // updated one, start a new task to update its icon as well. + if (!mPage.bookmarkedSpec.IsEmpty() && + !mPage.bookmarkedSpec.Equals(mPage.spec)) { + // Create a new page struct to avoid polluting it with old data. + PageData bookmarkedPage; + bookmarkedPage.spec = mPage.bookmarkedSpec; + + // This will be silent, so be sure to not pass in the current callback. + nsCOMPtr nullCallback; + nsRefPtr event = + new AsyncAssociateIconToPage(mIcon, bookmarkedPage, nullCallback); + mDB->DispatchToAsyncThread(event); + } +} + } // namespace places } // namespace mozilla diff --git a/toolkit/components/places/AsyncFaviconHelpers.h b/toolkit/components/places/AsyncFaviconHelpers.h index bf1628074b69..1db08f4abe01 100644 --- a/toolkit/components/places/AsyncFaviconHelpers.h +++ b/toolkit/components/places/AsyncFaviconHelpers.h @@ -259,8 +259,8 @@ protected: }; /** - * Asynchronously tries to get the URL of a page's favicon. If this succeeds, - * notifies the given observer. + * Asynchronously tries to get the URL of a page's favicon, then notifies the + * given observer. */ class AsyncGetFaviconURLForPage : public AsyncFaviconHelperBase { @@ -273,7 +273,7 @@ public: * @param aPageURI * URL of the page whose favicon's URL we're fetching * @param aCallback - * function to be called once the URL is retrieved from the database + * function to be called once finished */ static nsresult start(nsIURI* aPageURI, nsIFaviconDataCallback* aCallback); @@ -284,7 +284,7 @@ public: * @param aPageSpec * URL of the page whose favicon's URL we're fetching * @param aCallback - * function to be called once the URL is retrieved from the database + * function to be called once finished */ AsyncGetFaviconURLForPage(const nsACString& aPageSpec, nsCOMPtr& aCallback); @@ -297,8 +297,8 @@ private: /** - * Asynchronously tries to get the URL and data of a page's favicon. - * If this succeeds, notifies the given observer. + * Asynchronously tries to get the URL and data of a page's favicon, then + * notifies the given observer. */ class AsyncGetFaviconDataForPage : public AsyncFaviconHelperBase { @@ -311,7 +311,7 @@ public: * @param aPageURI * URL of the page whose favicon URL and data we're fetching * @param aCallback - * function to be called once the URL and data is retrieved from the database + * function to be called once finished */ static nsresult start(nsIURI* aPageURI, nsIFaviconDataCallback* aCallback); @@ -322,7 +322,7 @@ public: * @param aPageSpec * URL of the page whose favicon URL and data we're fetching * @param aCallback - * function to be called once the URL is retrieved from the database + * function to be called once finished */ AsyncGetFaviconDataForPage(const nsACString& aPageSpec, nsCOMPtr& aCallback); @@ -370,6 +370,16 @@ class NotifyIconObservers : public AsyncFaviconHelperBase public: NS_DECL_NSIRUNNABLE + /** + * Constructor. + * + * @param aIcon + * Icon information. Can be empty if no icon is associated to the page. + * @param aPage + * Page to which the icon information applies. + * @param aCallback + * Function to be notified in all cases. + */ NotifyIconObservers(IconData& aIcon, PageData& aPage, nsCOMPtr& aCallback); @@ -378,6 +388,8 @@ public: protected: IconData mIcon; PageData mPage; + + void SendGlobalNotifications(nsIURI* aIconURI); }; } // namespace places diff --git a/toolkit/components/places/mozIAsyncFavicons.idl b/toolkit/components/places/mozIAsyncFavicons.idl index 063b82d6dc22..0d89500a32c6 100644 --- a/toolkit/components/places/mozIAsyncFavicons.idl +++ b/toolkit/components/places/mozIAsyncFavicons.idl @@ -160,14 +160,18 @@ interface mozIAsyncFavicons : nsISupports [optional] in PRTime aExpiration); /** - * Retrieve the URL of the favicon for the given page. + * Retrieves the favicon URI associated to the given page, if any. * * @param aPageURI - * URI of the page whose favicon's URL we're looking up + * URI of the page whose favicon URI we're looking up. * @param aCallback - * Once we've found the favicon's URL, we invoke this callback. Note - * that the callback's aDataLen will be 0, aData will be null, and - * aMimeType will be empty -- only aURI will be non-zero/null/empty. + * This callback is always invoked to notify the result of the lookup. + * The aURI parameter will be the favicon URI, or null when no favicon + * is associated with the page or an error occurred while fetching it. + * + * @note When the callback is invoked, aDataLen will be always 0, aData will + * be an empty array, and aMimeType will be an empty string, regardless + * of whether a favicon is associated with the page. * * @see nsIFaviconDataCallback in nsIFaviconService.idl. */ @@ -175,13 +179,18 @@ interface mozIAsyncFavicons : nsISupports in nsIFaviconDataCallback aCallback); /** - * Retrieve the URL and data of the favicon for the given page. + * Retrieves the favicon URI and data associated to the given page, if any. * * @param aPageURI - * URI of the page whose favicon's URL and data we're looking up + * URI of the page whose favicon URI and data we're looking up. * @param aCallback - * Once we've found the favicon's URL, we invoke this callback with - * the favicon data. + * This callback is always invoked to notify the result of the lookup. The aURI + * parameter will be the favicon URI, or null when no favicon is + * associated with the page or an error occurred while fetching it. If + * aURI is not null, the other parameters may contain the favicon data. + * However, if no favicon data is currently associated with the favicon + * URI, aDataLen will be 0, aData will be an empty array, and aMimeType + * will be an empty string. * * @see nsIFaviconDataCallback in nsIFaviconService.idl. */ diff --git a/toolkit/components/places/nsIFaviconService.idl b/toolkit/components/places/nsIFaviconService.idl index 8eb0a70f3f77..2b9f82646867 100644 --- a/toolkit/components/places/nsIFaviconService.idl +++ b/toolkit/components/places/nsIFaviconService.idl @@ -328,14 +328,14 @@ interface nsIFaviconService : nsISupports readonly attribute nsIURI defaultFavicon; }; -[scriptable, function, uuid(22ebd780-f4ab-11de-8a39-0800200c9a66)] +[scriptable, function, uuid(c85e5c82-b70f-4621-9528-beb2aa47fb44)] interface nsIFaviconDataCallback : nsISupports { /** * Called when the required favicon's information is available. * - * This callback will be called only if the operation is successful, otherwise - * you won't get notified. + * It's up to the invoking method to state if the callback is always invoked, + * or called on success only. Check the method documentation to ensure that. * * The caller will receive the most information we can gather on the icon, * but it's not guaranteed that all of them will be set. For some method @@ -344,23 +344,26 @@ interface nsIFaviconDataCallback : nsISupports * It's up to the caller to check aDataLen > 0 before using any data-related * information like mime-type or data itself. * - * @param aURI - * Depending on caller method it could be: - * - a dataURI: has "data:" scheme, with base64 encoded icon data. - * - a faviconURI: the URI of the icon in the favicon service. - * - a faviconLinkURI: has "moz-anno" scheme, used to get data async. + * @param aFaviconURI + * Receives the "favicon URI" (not the "favicon link URI") associated + * to the requested page. This can be null if there is no associated + * favicon URI, or the callback is notifying a failure. * @param aDataLen * Size of the icon data in bytes. Notice that a value of 0 does not * necessarily mean that we don't have an icon. * @param aData - * Icon data, null if aDataLen is 0. + * Icon data, or an empty array if aDataLen is 0. * @param aMimeType - * Mime type of the icon, null if aDataLen is 0. + * Mime type of the icon, or an empty string if aDataLen is 0. + * + * @note If you want to open a network channel to access the favicon, it's + * recommended that you call the getFaviconLinkForIcon method to convert + * the "favicon URI" into a "favicon link URI". */ - void onFaviconDataAvailable(in nsIURI aURI, - in unsigned long aDataLen, - [const,array,size_is(aDataLen)] in octet aData, - in AUTF8String aMimeType); + void onComplete(in nsIURI aFaviconURI, + in unsigned long aDataLen, + [const,array,size_is(aDataLen)] in octet aData, + in AUTF8String aMimeType); }; %{C++ diff --git a/toolkit/components/places/tests/favicons/head_favicons.js b/toolkit/components/places/tests/favicons/head_favicons.js index 04f83419df78..29c696345222 100644 --- a/toolkit/components/places/tests/favicons/head_favicons.js +++ b/toolkit/components/places/tests/favicons/head_favicons.js @@ -103,7 +103,7 @@ function waitForFaviconChanged(aExpectedPageURI, aExpectedFaviconURI, function checkFaviconDataForPage(aPageURI, aExpectedMimeType, aExpectedData, aCallback) { PlacesUtils.favicons.getFaviconDataForPage(aPageURI, - function CFDFP_onFaviconDataAvailable(aURI, aDataLen, aData, aMimeType) { + function (aURI, aDataLen, aData, aMimeType) { do_check_eq(aExpectedMimeType, aMimeType); do_check_true(compareArrays(aExpectedData, aData)); do_check_guid_for_uri(aPageURI); @@ -120,21 +120,9 @@ function checkFaviconDataForPage(aPageURI, aExpectedMimeType, aExpectedData, * This function is called after the check finished. */ function checkFaviconMissingForPage(aPageURI, aCallback) { - // Ask for the favicon associated with the page, expecting not to be notified. - let notificationReceived = false; PlacesUtils.favicons.getFaviconURLForPage(aPageURI, - function CFMFP_onFaviconDataAvailable() { - notificationReceived = true; - }); - - // We must wait for the asynchronous database thread to finish the operation, - // and then for the main thread to process any pending notifications that came - // from the asynchronous thread, before we can be sure that - // onFaviconDataAvailable was not invoked in the meantime. - waitForAsyncUpdates(function CFMFP_asyncUpdates() { - do_execute_soon(function CFMFP_soon() { - do_check_false(notificationReceived); + function (aURI, aDataLen, aData, aMimeType) { + do_check_true(aURI === null); aCallback(); }); - }); } diff --git a/toolkit/components/places/tests/favicons/test_expireAllFavicons.js b/toolkit/components/places/tests/favicons/test_expireAllFavicons.js index 4703a1a46527..8f3196a652a4 100644 --- a/toolkit/components/places/tests/favicons/test_expireAllFavicons.js +++ b/toolkit/components/places/tests/favicons/test_expireAllFavicons.js @@ -42,8 +42,7 @@ add_test(function test_expireAllFavicons() { PlacesUtils.bookmarks.DEFAULT_INDEX, "Test bookmark"); PlacesUtils.favicons.setAndFetchFaviconForPage( - BOOKMARKED_PAGE_URI, SMALLPNG_DATA_URI, true, - function EAF_onFaviconDataAvailable() { + BOOKMARKED_PAGE_URI, SMALLPNG_DATA_URI, true, function () { // Start expiration only after data has been saved in the database. PlacesUtils.favicons.expireAllFavicons(); }); diff --git a/toolkit/components/places/tests/favicons/test_favicons.js b/toolkit/components/places/tests/favicons/test_favicons.js index d2dfe9607927..0364de5b5354 100644 --- a/toolkit/components/places/tests/favicons/test_favicons.js +++ b/toolkit/components/places/tests/favicons/test_favicons.js @@ -78,7 +78,7 @@ add_test(function test_set_and_get_favicon_setup() { add_test(function test_set_and_get_favicon_getFaviconURLForPage() { let [icon0] = icons; PlacesUtils.favicons.getFaviconURLForPage(pages[0], - function GFUFP_onFaviconDataAvailable(aURI, aDataLen, aData, aMimeType) { + function (aURI, aDataLen, aData, aMimeType) { do_check_true(icon0.uri.equals(aURI)); do_check_eq(aDataLen, 0); do_check_eq(aData.length, 0); diff --git a/toolkit/components/places/tests/favicons/test_getFaviconDataForPage.js b/toolkit/components/places/tests/favicons/test_getFaviconDataForPage.js new file mode 100644 index 000000000000..7ccbf118a2b0 --- /dev/null +++ b/toolkit/components/places/tests/favicons/test_getFaviconDataForPage.js @@ -0,0 +1,57 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * This file tests getFaviconDataForPage. + */ + +//////////////////////////////////////////////////////////////////////////////// +/// Globals + +const FAVICON_URI = NetUtil.newURI(do_get_file("favicon-normal32.png")); +const FAVICON_DATA = readFileData(do_get_file("favicon-normal32.png")); +const FAVICON_MIMETYPE = "image/png"; + +//////////////////////////////////////////////////////////////////////////////// +/// Tests + +function run_test() +{ + // Check that the favicon loaded correctly before starting the actual tests. + do_check_eq(FAVICON_DATA.length, 344); + run_next_test(); +} + +add_test(function test_normal() +{ + let pageURI = NetUtil.newURI("http://example.com/normal"); + + addVisits(pageURI, function () { + PlacesUtils.favicons.setAndFetchFaviconForPage( + pageURI, FAVICON_URI, true, function () { + PlacesUtils.favicons.getFaviconDataForPage(pageURI, + function (aURI, aDataLen, aData, aMimeType) { + do_check_true(aURI.equals(FAVICON_URI)); + do_check_eq(FAVICON_DATA.length, aDataLen); + do_check_true(compareArrays(FAVICON_DATA, aData)); + do_check_eq(FAVICON_MIMETYPE, aMimeType); + run_next_test(); + }); + }); + }); +}); + +add_test(function test_missing() +{ + let pageURI = NetUtil.newURI("http://example.com/missing"); + + PlacesUtils.favicons.getFaviconDataForPage(pageURI, + function (aURI, aDataLen, aData, aMimeType) { + // Check also the expected data types. + do_check_true(aURI === null); + do_check_true(aDataLen === 0); + do_check_true(aData.length === 0); + do_check_true(aMimeType === ""); + run_next_test(); + }); +}); diff --git a/toolkit/components/places/tests/favicons/test_getFaviconURLForPage.js b/toolkit/components/places/tests/favicons/test_getFaviconURLForPage.js new file mode 100644 index 000000000000..208beda2d617 --- /dev/null +++ b/toolkit/components/places/tests/favicons/test_getFaviconURLForPage.js @@ -0,0 +1,50 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * This file tests getFaviconURLForPage. + */ + +//////////////////////////////////////////////////////////////////////////////// +/// Tests + +function run_test() +{ + run_next_test(); +} + +add_test(function test_normal() +{ + let pageURI = NetUtil.newURI("http://example.com/normal"); + + addVisits(pageURI, function () { + PlacesUtils.favicons.setAndFetchFaviconForPage( + pageURI, SMALLPNG_DATA_URI, true, function () { + PlacesUtils.favicons.getFaviconURLForPage(pageURI, + function (aURI, aDataLen, aData, aMimeType) { + do_check_true(aURI.equals(SMALLPNG_DATA_URI)); + + // Check also the expected data types. + do_check_true(aDataLen === 0); + do_check_true(aData.length === 0); + do_check_true(aMimeType === ""); + run_next_test(); + }); + }); + }); +}); + +add_test(function test_missing() +{ + let pageURI = NetUtil.newURI("http://example.com/missing"); + + PlacesUtils.favicons.getFaviconURLForPage(pageURI, + function (aURI, aDataLen, aData, aMimeType) { + // Check also the expected data types. + do_check_true(aURI === null); + do_check_true(aDataLen === 0); + do_check_true(aData.length === 0); + do_check_true(aMimeType === ""); + run_next_test(); + }); +}); diff --git a/toolkit/components/places/tests/favicons/xpcshell.ini b/toolkit/components/places/tests/favicons/xpcshell.ini index 9048836dc620..5efc35cd6ca2 100644 --- a/toolkit/components/places/tests/favicons/xpcshell.ini +++ b/toolkit/components/places/tests/favicons/xpcshell.ini @@ -9,6 +9,8 @@ fail-if = os == "android" [test_favicons_conversions.js] # Bug 676989: test fails consistently on Android fail-if = os == "android" +[test_getFaviconDataForPage.js] +[test_getFaviconURLForPage.js] [test_moz-anno_favicon_mime_type.js] [test_query_result_favicon_changed_on_child.js] [test_replaceFaviconData.js] diff --git a/toolkit/components/places/tests/unit/test_preventive_maintenance.js b/toolkit/components/places/tests/unit/test_preventive_maintenance.js index 06473dab25f8..ed5785c813c1 100644 --- a/toolkit/components/places/tests/unit/test_preventive_maintenance.js +++ b/toolkit/components/places/tests/unit/test_preventive_maintenance.js @@ -1242,9 +1242,8 @@ tests.push({ do_check_eq(as.getPageAnnotation(this._uri2, "anno"), "anno"); do_check_eq(as.getItemAnnotation(this._bookmarkId, "anno"), "anno"); - fs.getFaviconURLForPage(this._uri2, - function AC_onFaviconDataAvailable(aURI) { - do_check_true(aURI.equals(SMALLPNG_DATA_URI)); + fs.getFaviconURLForPage(this._uri2, function (aFaviconURI) { + do_check_true(aFaviconURI.equals(SMALLPNG_DATA_URI)); aCallback(); }); } diff --git a/widget/windows/JumpListBuilder.cpp b/widget/windows/JumpListBuilder.cpp index 6894402bf7c9..31cb444db74d 100644 --- a/widget/windows/JumpListBuilder.cpp +++ b/widget/windows/JumpListBuilder.cpp @@ -557,10 +557,10 @@ AsyncFaviconDataReady::AsyncFaviconDataReady(nsIURI *aNewURI, } NS_IMETHODIMP -AsyncFaviconDataReady::OnFaviconDataAvailable(nsIURI *aFaviconURI, - PRUint32 aDataLen, - const PRUint8 *aData, - const nsACString &aMimeType) +AsyncFaviconDataReady::OnComplete(nsIURI *aFaviconURI, + PRUint32 aDataLen, + const PRUint8 *aData, + const nsACString &aMimeType) { if (!aDataLen || !aData) { return NS_OK; From a4e2da87ad4de3ce702551e7eb40e6e109f09f47 Mon Sep 17 00:00:00 2001 From: Paolo Amadini Date: Thu, 12 Apr 2012 12:27:27 +0200 Subject: [PATCH 05/14] Bug 728142 - Replace old synchronous favicons calls in tabview. r=ttaubert --HG-- extra : rebase_source : 5dc2e1a50862eaa238cd16479dada60da507eb01 --- .../tabview/test/browser_tabview_bug600645.js | 22 +++++++++++++------ browser/components/tabview/ui.js | 22 +++++++++++++------ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/browser/components/tabview/test/browser_tabview_bug600645.js b/browser/components/tabview/test/browser_tabview_bug600645.js index 787f53be88f7..d06907ff1bc4 100644 --- a/browser/components/tabview/test/browser_tabview_bug600645.js +++ b/browser/components/tabview/test/browser_tabview_bug600645.js @@ -1,6 +1,12 @@ /* Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ */ +/** + * This file tests that, when there is an app tab that references an invalid + * favicon, the default favicon appears the group app tab tray, instead of an + * empty image that would not be visible. + */ + const fi = Cc["@mozilla.org/browser/favicon-service;1"]. getService(Ci.nsIFaviconService); @@ -40,18 +46,20 @@ function onTabPinned() { // code. executeSoon(function() { let iconSrc = $icon.attr("src"); - let hasData = true; - try { - fi.getFaviconDataAsDataURL(iconSrc); - } catch(e) { - hasData = false; - } - ok(!hasData, "The icon src doesn't return any data"); + // with moz-anno:favicon automatically redirects to the default favIcon // if the given url is invalid ok(/^moz-anno:favicon:/.test(iconSrc), "The icon url starts with moz-anno:favicon so the default fav icon would be displayed"); + // At this point, as an additional integrity check we could also verify + // that the iconSrc URI does not have any associated favicon data. This + // kind of check, however, is not easily supported by the asynchronous + // favicon API. Fortunately, the fact that we received the error event + // already indicates that the original favicon was not available. + // Morevover, since we are using a "moz-anno:favicon:" URI, we know that + // we'll not display an empty icon, but the default favicon. + // clean up gBrowser.removeTab(newTab); let endGame = function() { diff --git a/browser/components/tabview/ui.js b/browser/components/tabview/ui.js index 8ea8fa509b8f..6b4ac4a7235a 100644 --- a/browser/components/tabview/ui.js +++ b/browser/components/tabview/ui.js @@ -1695,7 +1695,7 @@ let UI = { // ---------- // Function: getFavIconUrlForTab - // Gets fav icon url for the given xul:tab. + // Gets the "favicon link URI" for the given xul:tab, or null if unavailable. getFavIconUrlForTab: function UI_getFavIconUrlForTab(tab, callback) { this._isImageDocument(tab, function(isImageDoc) { if (isImageDoc) { @@ -1709,12 +1709,20 @@ let UI = { callback(tabImage); } else { - // determine to load the default/cached icon or not and also ensure we don't show the default icon - // for about:-style error pages - let url = null; - if (this._shouldLoadFavIcon(tab)) - url = gFavIconService.getFaviconImageForPage(tab.linkedBrowser.currentURI).spec; - callback(url); + // ensure we don't show the default icon for about:-style error pages + if (!this._shouldLoadFavIcon(tab)) { + callback(null); + } else { + // determine to load the default/cached icon or not + gFavIconService.getFaviconURLForPage(tab.linkedBrowser.currentURI, + function (uri) { + if (!uri) { + callback(gFavIconService.defaultFavicon.spec); + } else { + callback(gFavIconService.getFaviconLinkForIcon(uri).spec); + } + }); + } } } }.bind(this)); From 1e2be0784bc98c50d74d880fbf210de50588be4f Mon Sep 17 00:00:00 2001 From: Paolo Amadini Date: Thu, 12 Apr 2012 12:27:36 +0200 Subject: [PATCH 06/14] Bug 728174 - Replace old synchronous favicons calls in the bookmarks HTML import. r=mak --HG-- extra : rebase_source : ddb3109fa13f41bdfb2f265f7850453905145a07 --- ...41-import-export-corrupt-bookmarks-html.js | 31 ++++--- .../places/tests/unit/test_bookmarks_html.js | 90 +++++++++++++++++-- .../components/places/BookmarkHTMLUtils.jsm | 16 ++-- .../components/places/nsPlacesExportService.h | 0 .../components/places/tests/head_common.js | 20 +++++ 5 files changed, 133 insertions(+), 24 deletions(-) mode change 100644 => 100755 toolkit/components/places/nsPlacesExportService.h diff --git a/browser/components/places/tests/unit/test_457441-import-export-corrupt-bookmarks-html.js b/browser/components/places/tests/unit/test_457441-import-export-corrupt-bookmarks-html.js index 6e5c82d7100f..c526b5f767a5 100644 --- a/browser/components/places/tests/unit/test_457441-import-export-corrupt-bookmarks-html.js +++ b/browser/components/places/tests/unit/test_457441-import-export-corrupt-bookmarks-html.js @@ -62,7 +62,7 @@ const LOAD_IN_SIDEBAR_ANNO = "bookmarkProperties/loadInSidebar"; const POST_DATA_ANNO = "bookmarkProperties/POSTData"; const TEST_FAVICON_PAGE_URL = "http://en-US.www.mozilla.com/en-US/firefox/central/"; -const TEST_FAVICON_DATA_URL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHWSURBVHjaYvz//z8DJQAggJiQOe/fv2fv7Oz8rays/N+VkfG/iYnJfyD/1+rVq7ffu3dPFpsBAAHEAHIBCJ85c8bN2Nj4vwsDw/8zQLwKiO8CcRoQu0DxqlWrdsHUwzBAAIGJmTNnPgYa9j8UqhFElwPxf2MIDeIrKSn9FwSJoRkAEEAM0DD4DzMAyPi/G+QKY4hh5WAXGf8PDQ0FGwJ22d27CjADAAIIrLmjo+MXA9R2kAHvGBA2wwx6B8W7od6CeQcggKCmCEL8bgwxYCbUIGTDVkHDBia+CuotgACCueD3TDQN75D4xmAvCoK9ARMHBzAw0AECiBHkAlC0Mdy7x9ABNA3obAZXIAa6iKEcGlMVQHwWyjYuL2d4v2cPg8vZswx7gHyAAAK7AOif7SAbOqCmn4Ha3AHFsIDtgPq/vLz8P4MSkJ2W9h8ggBjevXvHDo4FQUQg/kdypqCg4H8lUIACnQ/SOBMYI8bAsAJFPcj1AAEEjwVQqLpAbXmH5BJjqI0gi9DTAAgDBBCcAVLkgmQ7yKCZxpCQxqUZhAECCJ4XgMl493ug21ZD+aDAXH0WLM4A9MZPXJkJIIAwTAR5pQMalaCABQUULttBGCCAGCnNzgABBgAMJ5THwGvJLAAAAABJRU5ErkJggg=="; +const TEST_FAVICON_DATA_SIZE = 580; function run_test() { do_test_pending(); @@ -84,8 +84,7 @@ function after_import(success) { // Check that every bookmark is correct // Corrupt bookmarks should not have been imported - database_check(); - waitForAsyncUpdates(function() { + database_check(function () { // Create corruption in database var corruptItemId = bs.insertBookmark(bs.toolbarFolder, uri("http://test.mozilla.org"), @@ -112,22 +111,23 @@ function after_import(success) { // Import bookmarks try { - BookmarkHTMLUtils.importFromFile(bookmarksFile, true, before_database_check); + BookmarkHTMLUtils.importFromFile(bookmarksFile, true, before_database_check); } catch(ex) { do_throw("couldn't import the exported file: " + ex); } }); } function before_database_check(success) { - // Check that every bookmark is correct - database_check(); - - waitForAsyncUpdates(do_test_finished); + // Check that every bookmark is correct + database_check(do_test_finished); } /* * Check for imported bookmarks correctness + * + * @param aCallback + * Called when the checks are finished. */ -function database_check() { +function database_check(aCallback) { // BOOKMARKS MENU var query = hs.getNewQuery(); query.setFolders([bs.bookmarksMenuFolder], 1); @@ -226,7 +226,14 @@ function database_check() { unfiledBookmarks.containerOpen = false; // favicons - var faviconURI = icos.getFaviconForPage(uri(TEST_FAVICON_PAGE_URL)); - var dataURL = icos.getFaviconDataAsDataURL(faviconURI); - do_check_eq(TEST_FAVICON_DATA_URL, dataURL); + icos.getFaviconDataForPage(uri(TEST_FAVICON_PAGE_URL), + function DC_onComplete(aURI, aDataLen, aData, aMimeType) { + // aURI should never be null when aDataLen > 0. + do_check_neq(aURI, null); + // Favicon data is stored in the bookmarks file as a "data:" URI. For + // simplicity, instead of converting the data we receive to a "data:" URI + // and comparing it, we just check the data size. + do_check_eq(TEST_FAVICON_DATA_SIZE, aDataLen); + aCallback(); + }); } diff --git a/browser/components/places/tests/unit/test_bookmarks_html.js b/browser/components/places/tests/unit/test_bookmarks_html.js index aa4772c7b73b..7651f27fd13e 100644 --- a/browser/components/places/tests/unit/test_bookmarks_html.js +++ b/browser/components/places/tests/unit/test_bookmarks_html.js @@ -183,11 +183,14 @@ add_test(function test_emptytitle_export() { // Test exporting and importing with an empty-titled bookmark. // 1. import bookmarks - // 1. create an empty-titled bookmark. - // 2. export to bookmarks.exported.html - // 3. empty bookmarks db - // 4. import bookmarks.exported.html - // 5. run the test-suite + // 2. create an empty-titled bookmark. + // 3. export to bookmarks.exported.html + // 4. empty bookmarks db + // 5. import bookmarks.exported.html + // 6. run the test-suite + // 7. remove the empty-titled bookmark + // 8. export to bookmarks.exported.html + // 9. empty bookmarks db and continue try { BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true, function(success) { @@ -236,6 +239,83 @@ add_test(function test_emptytitle_export() } catch(ex) { do_throw("couldn't import the exported file: " + ex); } }); +add_test(function test_import_chromefavicon() +{ + // Test exporting and importing with a bookmark pointing to a chrome favicon. + // 1. import bookmarks + // 2. create a bookmark pointing to a chrome favicon. + // 3. export to bookmarks.exported.html + // 4. empty bookmarks db + // 5. import bookmarks.exported.html + // 6. run the test-suite + // 7. remove the bookmark pointing to a chrome favicon. + // 8. export to bookmarks.exported.html + // 9. empty bookmarks db and continue + + const PAGE_URI = NetUtil.newURI("http://example.com/chromefavicon_page"); + const CHROME_FAVICON_URI = NetUtil.newURI("chrome://global/skin/icons/information-16.png"); + const CHROME_FAVICON_URI_2 = NetUtil.newURI("chrome://global/skin/icons/error-16.png"); + + try { + BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true, function(success) { + if (!success) { + do_throw("couldn't import the exported file."); + } + let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, + PAGE_URI, + PlacesUtils.bookmarks.DEFAULT_INDEX, + "Test"); + + PlacesUtils.favicons.setAndFetchFaviconForPage( + PAGE_URI, CHROME_FAVICON_URI, true, function () { + PlacesUtils.favicons.getFaviconDataForPage( + PAGE_URI, function (aURI, aDataLen, aData, aMimeType) { + let base64Icon = "data:image/png;base64," + + base64EncodeString(String.fromCharCode.apply(String, aData)); + + test_bookmarks.unfiled.push( + { title: "Test", url: PAGE_URI.spec, icon: base64Icon }); + + try { + exporter.exportHTMLToFile(gBookmarksFileNew); + } catch(ex) { do_throw("couldn't export to file: " + ex); } + + // Change the favicon to check it's really imported again later. + PlacesUtils.favicons.setAndFetchFaviconForPage( + PAGE_URI, CHROME_FAVICON_URI_2, true, function () { + + remove_all_bookmarks(); + + try { + BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true, function(success) { + if (!success) { + do_throw("couldn't import the exported file."); + } + waitForAsyncUpdates(function () { + testImportedBookmarks(); + + // Cleanup. + test_bookmarks.unfiled.pop(); + PlacesUtils.bookmarks.removeItem(id); + + try { + exporter.exportHTMLToFile(gBookmarksFileNew); + } catch(ex) { do_throw("couldn't export to file: " + ex); } + + waitForAsyncUpdates(function () { + remove_all_bookmarks(); + run_next_test(); + }); + }); + }); + } catch(ex) { do_throw("couldn't import the exported file: " + ex); } + }); + }); + }); + }); + } catch(ex) { do_throw("couldn't import the exported file: " + ex); } +}); + add_test(function test_import_ontop() { // Test importing the exported bookmarks.html file *on top of* the existing diff --git a/toolkit/components/places/BookmarkHTMLUtils.jsm b/toolkit/components/places/BookmarkHTMLUtils.jsm index e2cd4d0116df..25757445d8b5 100644 --- a/toolkit/components/places/BookmarkHTMLUtils.jsm +++ b/toolkit/components/places/BookmarkHTMLUtils.jsm @@ -621,7 +621,8 @@ BookmarkImporter.prototype = { // worry about data if (aIconURI) { if (aIconURI.scheme == "chrome") { - PlacesUtils.favicons.setFaviconUrlForPage(aPageURI, aIconURI); + PlacesUtils.favicons.setAndFetchFaviconForPage(aPageURI, aIconURI, + false); return; } } @@ -636,7 +637,9 @@ BookmarkImporter.prototype = { if (aIconURI) { faviconURI = aIconURI; } else { - // make up favicon URL + // Make up a favicon URI for this page. Later, we'll make sure that this + // favicon URI is always associated with local favicon data, so that we + // don't load this URI from the network. let faviconSpec = "http://www.mozilla.org/2005/made-up-favicon/" + serialNumber + "-" @@ -645,12 +648,11 @@ BookmarkImporter.prototype = { serialNumber++; } - // save the favicon data // This could fail if the favicon is bigger than defined limit, in such a - // case data will not be saved to the db but we will still continue. - PlacesUtils.favicons.setFaviconDataFromDataURL(faviconURI, aData, 0); - - PlacesUtils.favicons.setFaviconUrlForPage(aPageURI, faviconURI); + // case neither the favicon URI nor the favicon data will be saved. If the + // bookmark is visited again later, the URI and data will be fetched. + PlacesUtils.favicons.replaceFaviconDataFromDataURL(faviconURI, aData); + PlacesUtils.favicons.setAndFetchFaviconForPage(aPageURI, faviconURI, false); }, /** diff --git a/toolkit/components/places/nsPlacesExportService.h b/toolkit/components/places/nsPlacesExportService.h old mode 100644 new mode 100755 diff --git a/toolkit/components/places/tests/head_common.js b/toolkit/components/places/tests/head_common.js index 271cf1e7d879..33b0d76fe2cf 100644 --- a/toolkit/components/places/tests/head_common.js +++ b/toolkit/components/places/tests/head_common.js @@ -200,6 +200,26 @@ function readFileOfLength(aFileName, aExpectedLength) { } +/** + * Returns the base64-encoded version of the given string. This function is + * similar to window.btoa, but is available to xpcshell tests also. + * + * @param aString + * Each character in this string corresponds to a byte, and must be a + * code point in the range 0-255. + * + * @return The base64-encoded string. + */ +function base64EncodeString(aString) { + var stream = Cc["@mozilla.org/io/string-input-stream;1"] + .createInstance(Ci.nsIStringInputStream); + stream.setData(aString, aString.length); + var encoder = Cc["@mozilla.org/scriptablebase64encoder;1"] + .createInstance(Ci.nsIScriptableBase64Encoder); + return encoder.encodeToString(stream, aString.length); +} + + /** * Compares two arrays, and returns true if they are equal. * From 70cac11c6400b0b0a4f267519fd9e68cc74c22be Mon Sep 17 00:00:00 2001 From: Paolo Amadini Date: Thu, 12 Apr 2012 12:27:45 +0200 Subject: [PATCH 07/14] Bug 741175 - Document skipping Places tests because the Private Browsing service is unavailable. r=mak --HG-- extra : rebase_source : 5ccac27d1787a483a41690a0bd042a060ac4ab18 --- .../test_setAndFetchFaviconForPage.js | 1 + ...test_setAndFetchFaviconForPage_failures.js | 1 + .../tests/unit/test_download_history.js | 56 ++++++++++--------- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/toolkit/components/places/tests/favicons/test_setAndFetchFaviconForPage.js b/toolkit/components/places/tests/favicons/test_setAndFetchFaviconForPage.js index fa112a0f4b91..bdb2d18098b0 100644 --- a/toolkit/components/places/tests/favicons/test_setAndFetchFaviconForPage.js +++ b/toolkit/components/places/tests/favicons/test_setAndFetchFaviconForPage.js @@ -54,6 +54,7 @@ add_test(function test_aboutURI_bookmarked() add_test(function test_privateBrowsing_bookmarked() { if (!("@mozilla.org/privatebrowsing;1" in Cc)) { + do_log_info("Private Browsing service is not available, bail out."); run_next_test(); return; } diff --git a/toolkit/components/places/tests/favicons/test_setAndFetchFaviconForPage_failures.js b/toolkit/components/places/tests/favicons/test_setAndFetchFaviconForPage_failures.js index d8a113acedae..4f498b40d53a 100644 --- a/toolkit/components/places/tests/favicons/test_setAndFetchFaviconForPage_failures.js +++ b/toolkit/components/places/tests/favicons/test_setAndFetchFaviconForPage_failures.js @@ -87,6 +87,7 @@ add_test(function test_aboutURI() add_test(function test_privateBrowsing_nonBookmarkedURI() { if (!("@mozilla.org/privatebrowsing;1" in Cc)) { + do_log_info("Private Browsing service is not available, bail out."); run_next_test(); return; } diff --git a/toolkit/components/places/tests/unit/test_download_history.js b/toolkit/components/places/tests/unit/test_download_history.js index 54dda25c1e3a..f9fc11934428 100644 --- a/toolkit/components/places/tests/unit/test_download_history.js +++ b/toolkit/components/places/tests/unit/test_download_history.js @@ -124,36 +124,40 @@ add_test(function test_dh_addDownload_referrer() }); }); -if ("@mozilla.org/privatebrowsing;1" in Cc) { - add_test(function test_dh_addDownload_privateBrowsing() - { - waitForOnVisit(function DHAD_onVisit(aURI) { - // We should only receive the notification for the non-private URI. This - // test is based on the assumption that visit notifications are received - // in the same order of the addDownload calls, which is currently true - // because database access is serialized on the same worker thread. - do_check_true(aURI.equals(DOWNLOAD_URI)); +add_test(function test_dh_addDownload_privateBrowsing() +{ + if (!("@mozilla.org/privatebrowsing;1" in Cc)) { + do_log_info("Private Browsing service is not available, bail out."); + run_next_test(); + return; + } - uri_in_db(DOWNLOAD_URI, true); - uri_in_db(PRIVATE_URI, false); + waitForOnVisit(function DHAD_onVisit(aURI) { + // We should only receive the notification for the non-private URI. This + // test is based on the assumption that visit notifications are received + // in the same order of the addDownload calls, which is currently true + // because database access is serialized on the same worker thread. + do_check_true(aURI.equals(DOWNLOAD_URI)); - waitForClearHistory(run_next_test); - }); + uri_in_db(DOWNLOAD_URI, true); + uri_in_db(PRIVATE_URI, false); - let pb = Cc["@mozilla.org/privatebrowsing;1"] - .getService(Ci.nsIPrivateBrowsingService); - Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", - true); - pb.privateBrowsingEnabled = true; - gDownloadHistory.addDownload(PRIVATE_URI, REFERRER_URI, Date.now() * 1000); - - // The addDownload functions calls CanAddURI synchronously, thus we can - // exit Private Browsing Mode immediately. - pb.privateBrowsingEnabled = false; - Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session"); - gDownloadHistory.addDownload(DOWNLOAD_URI, REFERRER_URI, Date.now() * 1000); + waitForClearHistory(run_next_test); }); -} + + let pb = Cc["@mozilla.org/privatebrowsing;1"] + .getService(Ci.nsIPrivateBrowsingService); + Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", + true); + pb.privateBrowsingEnabled = true; + gDownloadHistory.addDownload(PRIVATE_URI, REFERRER_URI, Date.now() * 1000); + + // The addDownload functions calls CanAddURI synchronously, thus we can + // exit Private Browsing Mode immediately. + pb.privateBrowsingEnabled = false; + Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session"); + gDownloadHistory.addDownload(DOWNLOAD_URI, REFERRER_URI, Date.now() * 1000); +}); add_test(function test_dh_addDownload_disabledHistory() { From 0bfd44989d23ed8fbcec60edd1e03add9c8a3ab3 Mon Sep 17 00:00:00 2001 From: Paolo Amadini Date: Thu, 12 Apr 2012 12:27:57 +0200 Subject: [PATCH 08/14] Bug 715355 - Deprecate and remove old style GUIDs. r=mak --HG-- extra : rebase_source : 0d0a2ac825ed674075e8e85607a496668953c6c1 --- .../places/tests/browser/Makefile.in | 1 - .../browser/browser_457473_no_copy_guid.js | 146 ------------------ .../unit/test_bookmark_smart_bookmarks.js | 1 - toolkit/components/places/Database.cpp | 48 ++++++ toolkit/components/places/Database.h | 3 +- toolkit/components/places/PlacesDBUtils.jsm | 1 + toolkit/components/places/PlacesUtils.jsm | 37 ----- .../places/nsINavBookmarksService.idl | 32 +--- toolkit/components/places/nsNavBookmarks.cpp | 100 ------------ toolkit/components/places/nsNavBookmarks.h | 3 - .../places/tests/bookmarks/test_360134.js | 81 ---------- .../places/tests/bookmarks/test_484026.js | 62 -------- .../tests/bookmarks/test_restore_guids.js | 118 -------------- .../places/tests/bookmarks/xpcshell.ini | 3 - .../components/places/tests/head_common.js | 2 +- .../places/tests/migration/places_v19.sqlite | Bin 0 -> 1179648 bytes .../tests/migration/test_current_from_v19.js | 62 ++++++++ .../places/tests/migration/xpcshell.ini | 1 + .../places/tests/unit/test_null_interfaces.js | 2 +- .../tests/unit/test_preventive_maintenance.js | 93 +++++++++++ .../places/tests/unit/test_txnGUIDs.js | 105 ------------- .../components/places/tests/unit/xpcshell.ini | 1 - 22 files changed, 210 insertions(+), 692 deletions(-) delete mode 100644 browser/components/places/tests/browser/browser_457473_no_copy_guid.js delete mode 100644 toolkit/components/places/tests/bookmarks/test_360134.js delete mode 100644 toolkit/components/places/tests/bookmarks/test_484026.js delete mode 100644 toolkit/components/places/tests/bookmarks/test_restore_guids.js create mode 100644 toolkit/components/places/tests/migration/places_v19.sqlite create mode 100644 toolkit/components/places/tests/migration/test_current_from_v19.js delete mode 100644 toolkit/components/places/tests/unit/test_txnGUIDs.js diff --git a/browser/components/places/tests/browser/Makefile.in b/browser/components/places/tests/browser/Makefile.in index 224641a3cc36..b55809c37f4f 100644 --- a/browser/components/places/tests/browser/Makefile.in +++ b/browser/components/places/tests/browser/Makefile.in @@ -51,7 +51,6 @@ _BROWSER_TEST_FILES = \ browser_475045.js \ browser_423515.js \ browser_410196_paste_into_tags.js \ - browser_457473_no_copy_guid.js \ browser_sort_in_library.js \ browser_library_open_leak.js \ browser_library_panel_leak.js \ diff --git a/browser/components/places/tests/browser/browser_457473_no_copy_guid.js b/browser/components/places/tests/browser/browser_457473_no_copy_guid.js deleted file mode 100644 index 6a83a99495b2..000000000000 --- a/browser/components/places/tests/browser/browser_457473_no_copy_guid.js +++ /dev/null @@ -1,146 +0,0 @@ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Places test code. - * - * The Initial Developer of the Original Code is the Mozilla Foundation. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Dietrich Ayala - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -function test() { - // sanity check - ok(PlacesUtils, "checking PlacesUtils, running in chrome context?"); - ok(PlacesUIUtils, "checking PlacesUIUtils, running in chrome context?"); - - /* - - create, a test folder, add bookmark, separator to it - - fetch guids for all - - copy the folder - - test that guids are all different - - undo copy - - redo copy - - test that guids for the copy stay the same - */ - - var toolbarId = PlacesUtils.toolbarFolderId; - var toolbarNode = PlacesUtils.getFolderContents(toolbarId).root; - - var oldCount = toolbarNode.childCount; - var testRootId = PlacesUtils.bookmarks.createFolder(toolbarId, "test root", -1); - is(toolbarNode.childCount, oldCount+1, "confirm test root node is a container, and is empty"); - var testRootNode = toolbarNode.getChild(toolbarNode.childCount-1); - PlacesUtils.asContainer(testRootNode); - testRootNode.containerOpen = true; - is(testRootNode.childCount, 0, "confirm test root node is a container, and is empty"); - - // create folder A, fill it w/ each item type - var folderAId = PlacesUtils.bookmarks.createFolder(testRootId, "A", -1); - PlacesUtils.bookmarks.insertBookmark(folderAId, PlacesUtils._uri("http://foo"), - -1, "test bookmark"); - PlacesUtils.bookmarks.insertSeparator(folderAId, -1); - var folderANode = testRootNode.getChild(0); - var folderAGUIDs = getGUIDs(folderANode); - - // test the test function - ok(checkGUIDs(folderANode, folderAGUIDs, true), "confirm guid test works"); - - // serialize the folder - var serializedNode = PlacesUtils.wrapNode(folderANode, PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER); - var rawNode = PlacesUtils.unwrapNodes(serializedNode, PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER).shift(); - ok(rawNode.type, "confirm json node was made"); - - // Create a copy transaction from the serialization. - // this exercises the guid-filtering - var transaction = PlacesUIUtils.makeTransaction(rawNode, - PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER, - testRootId, -1, true); - ok(transaction, "create transaction"); - - // execute it, copying to the test root folder - PlacesUtils.transactionManager.doTransaction(transaction); - is(testRootNode.childCount, 2, "create test folder via copy"); - - // check GUIDs are different - var folderBNode = testRootNode.getChild(1); - ok(checkGUIDs(folderBNode, folderAGUIDs, false), "confirm folder A GUIDs don't match folder B GUIDs"); - var folderBGUIDs = getGUIDs(folderBNode); - ok(checkGUIDs(folderBNode, folderBGUIDs, true), "confirm test of new GUIDs"); - - // undo the transaction, confirm the removal - PlacesUtils.transactionManager.undoTransaction(); - is(testRootNode.childCount, 1, "confirm undo removed the copied folder"); - - // redo the transaction - // confirming GUIDs persist through undo/redo - PlacesUtils.transactionManager.redoTransaction(); - is(testRootNode.childCount, 2, "confirm redo re-copied the folder"); - folderBNode = testRootNode.getChild(1); - ok(checkGUIDs(folderBNode, folderAGUIDs, false), "folder B GUIDs after undo/redo don't match folder A GUIDs"); // sanity check - ok(checkGUIDs(folderBNode, folderBGUIDs, true), "folder B GUIDs after under/redo should match pre-undo/redo folder B GUIDs"); - - // Close containers, cleaning up their observers. - testRootNode.containerOpen = false; - toolbarNode.containerOpen = false; - - // clean up - PlacesUtils.transactionManager.undoTransaction(); - PlacesUtils.bookmarks.removeItem(testRootId); -} - -function getGUIDs(aNode) { - PlacesUtils.asContainer(aNode); - aNode.containerOpen = true; - var GUIDs = { - folder: PlacesUtils.bookmarks.getItemGUID(aNode.itemId), - bookmark: PlacesUtils.bookmarks.getItemGUID(aNode.getChild(0).itemId), - separator: PlacesUtils.bookmarks.getItemGUID(aNode.getChild(1).itemId) - }; - aNode.containerOpen = false; - return GUIDs; -} - -function checkGUIDs(aFolderNode, aGUIDs, aShouldMatch) { - - function check(aNode, aGUID, aEquals) { - var nodeGUID = PlacesUtils.bookmarks.getItemGUID(aNode.itemId); - return aEquals ? (nodeGUID == aGUID) : (nodeGUID != aGUID); - } - - PlacesUtils.asContainer(aFolderNode); - aFolderNode.containerOpen = true; - - var allMatch = check(aFolderNode, aGUIDs.folder, aShouldMatch) && - check(aFolderNode.getChild(0), aGUIDs.bookmark, aShouldMatch) && - check(aFolderNode.getChild(1), aGUIDs.separator, aShouldMatch) - - aFolderNode.containerOpen = false; - return allMatch; -} diff --git a/services/sync/tests/unit/test_bookmark_smart_bookmarks.js b/services/sync/tests/unit/test_bookmark_smart_bookmarks.js index 33907916cb90..2b8ef7baccfc 100644 --- a/services/sync/tests/unit/test_bookmark_smart_bookmarks.js +++ b/services/sync/tests/unit/test_bookmark_smart_bookmarks.js @@ -131,7 +131,6 @@ add_test(function test_annotation_uploaded() { // "Clear" by changing attributes: if we delete it, apparently it sticks // around as a deleted record... - PlacesUtils.bookmarks.setItemGUID(mostVisitedID, "abcdefabcdef"); PlacesUtils.bookmarks.setItemTitle(mostVisitedID, "Not Most Visited"); PlacesUtils.bookmarks.changeBookmarkURI( mostVisitedID, Utils.makeURI("http://something/else")); diff --git a/toolkit/components/places/Database.cpp b/toolkit/components/places/Database.cpp index 0bc65047acc2..ad2be7b6897c 100644 --- a/toolkit/components/places/Database.cpp +++ b/toolkit/components/places/Database.cpp @@ -760,6 +760,13 @@ Database::InitSchema(bool* aDatabaseMigrated) // Firefox 13 uses schema version 19. + if (currentSchemaVersion < 20) { + rv = MigrateV20Up(); + NS_ENSURE_SUCCESS(rv, rv); + } + + // Firefox 14 uses schema version 20. + // Schema Upgrades must add migration code here. rv = UpdateBookmarkRootTitles(); @@ -1299,6 +1306,7 @@ Database::MigrateV7Up() "WHERE root_name = :parent_name " ")"), getter_AddRefs(moveUnfiledBookmarks)); + NS_ENSURE_SUCCESS(rv, rv); rv = moveUnfiledBookmarks->BindUTF8StringByName( NS_LITERAL_CSTRING("root_name"), NS_LITERAL_CSTRING("unfiled") ); @@ -1776,6 +1784,7 @@ Database::MigrateV19Up() "WHERE b.type = :item_type AND n.name = :anno_name " ")" ), getter_AddRefs(deleteLivemarksChildrenStmt)); + NS_ENSURE_SUCCESS(rv, rv); rv = deleteLivemarksChildrenStmt->BindUTF8StringByName( NS_LITERAL_CSTRING("anno_name"), NS_LITERAL_CSTRING(LMANNO_FEEDURI) ); @@ -1800,6 +1809,7 @@ Database::MigrateV19Up() "WHERE name IN (:anno_loading, :anno_loadfailed, :anno_expiration) " ")" ), getter_AddRefs(deleteLivemarksAnnosStmt)); + NS_ENSURE_SUCCESS(rv, rv); rv = deleteLivemarksAnnosStmt->BindUTF8StringByName( NS_LITERAL_CSTRING("anno_loading"), NS_LITERAL_CSTRING("livemark/loading") ); @@ -1820,6 +1830,7 @@ Database::MigrateV19Up() "DELETE FROM moz_anno_attributes " "WHERE name IN (:anno_loading, :anno_loadfailed, :anno_expiration) " ), getter_AddRefs(deleteLivemarksAnnosStmt)); + NS_ENSURE_SUCCESS(rv, rv); rv = deleteLivemarksAnnosStmt->BindUTF8StringByName( NS_LITERAL_CSTRING("anno_loading"), NS_LITERAL_CSTRING("livemark/loading") ); @@ -1838,6 +1849,43 @@ Database::MigrateV19Up() return NS_OK; } +nsresult +Database::MigrateV20Up() +{ + MOZ_ASSERT(NS_IsMainThread()); + + // Remove obsolete bookmark GUID annotations. + nsCOMPtr deleteOldBookmarkGUIDAnnosStmt; + nsresult rv = mMainConn->CreateStatement(NS_LITERAL_CSTRING( + "DELETE FROM moz_items_annos WHERE anno_attribute_id = (" + "SELECT id FROM moz_anno_attributes " + "WHERE name = :anno_guid" + ")" + ), getter_AddRefs(deleteOldBookmarkGUIDAnnosStmt)); + NS_ENSURE_SUCCESS(rv, rv); + rv = deleteOldBookmarkGUIDAnnosStmt->BindUTF8StringByName( + NS_LITERAL_CSTRING("anno_guid"), NS_LITERAL_CSTRING("placesInternal/GUID") + ); + NS_ENSURE_SUCCESS(rv, rv); + rv = deleteOldBookmarkGUIDAnnosStmt->Execute(); + NS_ENSURE_SUCCESS(rv, rv); + + // Remove the orphan annotation name. + rv = mMainConn->CreateStatement(NS_LITERAL_CSTRING( + "DELETE FROM moz_anno_attributes " + "WHERE name = :anno_guid" + ), getter_AddRefs(deleteOldBookmarkGUIDAnnosStmt)); + NS_ENSURE_SUCCESS(rv, rv); + rv = deleteOldBookmarkGUIDAnnosStmt->BindUTF8StringByName( + NS_LITERAL_CSTRING("anno_guid"), NS_LITERAL_CSTRING("placesInternal/GUID") + ); + NS_ENSURE_SUCCESS(rv, rv); + rv = deleteOldBookmarkGUIDAnnosStmt->Execute(); + NS_ENSURE_SUCCESS(rv, rv); + + return NS_OK; +} + void Database::Shutdown() { diff --git a/toolkit/components/places/Database.h b/toolkit/components/places/Database.h index 121f283fdd15..46251f150096 100644 --- a/toolkit/components/places/Database.h +++ b/toolkit/components/places/Database.h @@ -47,7 +47,7 @@ // This is the schema version. Update it at any schema change and add a // corresponding migrateVxx method below. -#define DATABASE_SCHEMA_VERSION 19 +#define DATABASE_SCHEMA_VERSION 20 // Fired after Places inited. #define TOPIC_PLACES_INIT_COMPLETE "places-init-complete" @@ -302,6 +302,7 @@ protected: nsresult MigrateV17Up(); nsresult MigrateV18Up(); nsresult MigrateV19Up(); + nsresult MigrateV20Up(); nsresult UpdateBookmarkRootTitles(); nsresult CheckAndUpdateGUIDs(); diff --git a/toolkit/components/places/PlacesDBUtils.jsm b/toolkit/components/places/PlacesDBUtils.jsm index 341e649b5d67..e12aa6524a11 100644 --- a/toolkit/components/places/PlacesDBUtils.jsm +++ b/toolkit/components/places/PlacesDBUtils.jsm @@ -341,6 +341,7 @@ let PlacesDBUtils = { "WHERE anno_attribute_id IN ( " + " SELECT id FROM moz_anno_attributes " + " WHERE name = 'sync/children' " + + " OR name = 'placesInternal/GUID' " + " OR name BETWEEN 'weave/' AND 'weave0' " + ")"); cleanupStatements.push(deleteObsoleteItemsAnnos); diff --git a/toolkit/components/places/PlacesUtils.jsm b/toolkit/components/places/PlacesUtils.jsm index 20e914f2dcb6..cc0b91854c6a 100644 --- a/toolkit/components/places/PlacesUtils.jsm +++ b/toolkit/components/places/PlacesUtils.jsm @@ -131,7 +131,6 @@ var PlacesUtils = { TYPE_X_MOZ_PLACE_ACTION: "text/x-moz-place-action", EXCLUDE_FROM_BACKUP_ANNO: "places/excludeFromBackup", - GUID_ANNO: "placesInternal/GUID", LMANNO_FEEDURI: "livemark/feedURI", LMANNO_SITEURI: "livemark/siteURI", LMANNO_EXPIRATION: "livemark/expiration", @@ -2302,7 +2301,6 @@ TransactionItemCache.prototype = { this._parentId || -1, keyword: null, title: null, - guid: null, dateAdded: null, lastModified: null, postData: null, @@ -2486,9 +2484,6 @@ PlacesCreateFolderTransaction.prototype = { this.childTransactions); txn.doTransaction(); } - - if (this.item.guid) - PlacesUtils.bookmarks.setItemGUID(this.item.id, this.item.guid); }, undoTransaction: function CFTXN_undoTransaction() @@ -2499,11 +2494,6 @@ PlacesCreateFolderTransaction.prototype = { txn.undoTransaction(); } - // If a GUID exists for this item, preserve it before removing the item. - if (PlacesUtils.annotations.itemHasAnnotation(this.item.id, - PlacesUtils.GUID_ANNO)) - this.item.guid = PlacesUtils.bookmarks.getItemGUID(this.item.id); - // Remove item only after all child transactions have been reverted. PlacesUtils.bookmarks.removeItem(this.item.id); } @@ -2574,8 +2564,6 @@ PlacesCreateBookmarkTransaction.prototype = { this.childTransactions); txn.doTransaction(); } - if (this.item.guid) - PlacesUtils.bookmarks.setItemGUID(this.item.id, this.item.guid); }, undoTransaction: function CITXN_undoTransaction() @@ -2587,11 +2575,6 @@ PlacesCreateBookmarkTransaction.prototype = { txn.undoTransaction(); } - // If a GUID exists for this item, preserve it before removing the item. - if (PlacesUtils.annotations - .itemHasAnnotation(this.item.id, PlacesUtils.GUID_ANNO)) - this.item.guid = PlacesUtils.bookmarks.getItemGUID(this.item.id); - // Remove item only after all child transactions have been reverted. PlacesUtils.bookmarks.removeItem(this.item.id); } @@ -2622,17 +2605,10 @@ PlacesCreateSeparatorTransaction.prototype = { { this.item.id = PlacesUtils.bookmarks.insertSeparator(this.item.parentId, this.item.index); - if (this.item.guid) - PlacesUtils.bookmarks.setItemGUID(this.item.id, this.item.guid); }, undoTransaction: function CSTXN_undoTransaction() { - // If a GUID exists for this item, preserve it before removing the item. - if (PlacesUtils.annotations - .itemHasAnnotation(this.item.id, PlacesUtils.GUID_ANNO)) - this.item.guid = PlacesUtils.bookmarks.getItemGUID(this.item.id); - PlacesUtils.bookmarks.removeItem(this.item.id); } }; @@ -2689,8 +2665,6 @@ PlacesCreateLivemarkTransaction.prototype = { PlacesUtils.setAnnotationsForItem(this.item.id, this.item.annotations); } - if (this.item.guid) - PlacesUtils.bookmarks.setItemGUID(this.item.id, this.item.guid); } }).bind(this) ); @@ -2703,10 +2677,6 @@ PlacesCreateLivemarkTransaction.prototype = { PlacesUtils.livemarks.getLivemark( { id: this.item.id }, (function (aStatus, aLivemark) { - // If a GUID exists for this item, preserve it before removing the item. - if (PlacesUtils.annotations.itemHasAnnotation(this.item.id, PlacesUtils.GUID_ANNO)) - this.item.guid = PlacesUtils.bookmarks.getItemGUID(this.item.id); - PlacesUtils.bookmarks.removeItem(this.item.id); }).bind(this) ); @@ -3437,8 +3407,6 @@ PlacesTagURITransaction.prototype = { this.item.uri, PlacesUtils.bookmarks.DEFAULT_INDEX, PlacesUtils.history.getPageTitle(this.item.uri)); - if (this.item.guid) - PlacesUtils.bookmarks.setItemGUID(this.item.id, this.item.guid); } PlacesUtils.tagging.tagURI(this.item.uri, this.item.tags); }, @@ -3446,11 +3414,6 @@ PlacesTagURITransaction.prototype = { undoTransaction: function TUTXN_undoTransaction() { if (this.item.id != -1) { - // If a GUID exists for this item, preserve it before removing the item. - if (PlacesUtils.annotations - .itemHasAnnotation(this.item.id, PlacesUtils.GUID_ANNO)) { - this.item.guid = PlacesUtils.bookmarks.getItemGUID(this.item.id); - } PlacesUtils.bookmarks.removeItem(this.item.id); this.item.id = -1; } diff --git a/toolkit/components/places/nsINavBookmarksService.idl b/toolkit/components/places/nsINavBookmarksService.idl index 468e0be8cd54..5c3a09db5ea7 100644 --- a/toolkit/components/places/nsINavBookmarksService.idl +++ b/toolkit/components/places/nsINavBookmarksService.idl @@ -281,7 +281,7 @@ interface nsINavBookmarkObserver : nsISupports * folders. A URI in history can be contained in one or more such folders. */ -[scriptable, uuid(5398fdee-72d8-4100-9863-6bb7f88274e0)] +[scriptable, uuid(2299598b-8d83-4b67-9b13-b6d4707dcf7b)] interface nsINavBookmarksService : nsISupports { /** @@ -425,36 +425,6 @@ interface nsINavBookmarksService : nsISupports */ long long getIdForItemAt(in long long aParentId, in long aIndex); - /** - * Get a globally unique identifier for an item, meant to be used in - * sync scenarios. Even if their contents are exactly the same - * (including an item in a different profile with the same ItemId), - * the GUID would be different. - * @param aItemId - * The ID of the item to get the GUID for - * @return The GUID string. - */ - [deprecated] AString getItemGUID(in long long aItemId); - - /** - * Set a globally unique identifier. This can be useful when a sync - * algorithm deems two independently created items (on different - * profiles) to be the same item. - * @param aItemId - * The id of the item to set the GUID of - * @param aGUID - * The GUID string - */ - [deprecated] void setItemGUID(in long long aItemId, in AString aGUID); - - /** - * Get the ID of the item with the given GUID. - * @param aGUID - * The GUID string of the item to search for - * @return The item ID, or -1 if not found. - */ - [deprecated] long long getItemIdForGUID(in AString aGUID); - /** * Set the title for an item. * @param aItemId diff --git a/toolkit/components/places/nsNavBookmarks.cpp b/toolkit/components/places/nsNavBookmarks.cpp index 2481425bc3ed..1a501e548634 100644 --- a/toolkit/components/places/nsNavBookmarks.cpp +++ b/toolkit/components/places/nsNavBookmarks.cpp @@ -50,7 +50,6 @@ #include "nsNetUtil.h" #include "nsUnicharUtils.h" #include "nsPrintfCString.h" -#include "nsIUUIDGenerator.h" #include "prprf.h" #include "mozilla/storage.h" #include "mozilla/FunctionTimer.h" @@ -99,7 +98,6 @@ PLACES_FACTORY_SINGLETON_IMPLEMENTATION(nsNavBookmarks, gBookmarksService) #define BOOKMARKS_ANNO_PREFIX "bookmarks/" #define BOOKMARKS_TOOLBAR_FOLDER_ANNO NS_LITERAL_CSTRING(BOOKMARKS_ANNO_PREFIX "toolbarFolder") -#define GUID_ANNO NS_LITERAL_CSTRING("placesInternal/GUID") #define READ_ONLY_ANNO NS_LITERAL_CSTRING("placesInternal/READ_ONLY") @@ -1666,104 +1664,6 @@ nsNavBookmarks::GetItemLastModified(PRInt64 aItemId, PRTime* _lastModified) } -nsresult -nsNavBookmarks::GetGUIDBase(nsAString &aGUIDBase) -{ - if (!mGUIDBase.IsEmpty()) { - aGUIDBase = mGUIDBase; - return NS_OK; - } - - // generate a new GUID base for this session - nsCOMPtr uuidgen = - do_GetService("@mozilla.org/uuid-generator;1"); - NS_ENSURE_TRUE(uuidgen, NS_ERROR_OUT_OF_MEMORY); - nsID GUID; - nsresult rv = uuidgen->GenerateUUIDInPlace(&GUID); - NS_ENSURE_SUCCESS(rv, rv); - char GUIDChars[NSID_LENGTH]; - GUID.ToProvidedString(GUIDChars); - CopyASCIItoUTF16(GUIDChars, mGUIDBase); - aGUIDBase = mGUIDBase; - return NS_OK; -} - - -NS_IMETHODIMP -nsNavBookmarks::GetItemGUID(PRInt64 aItemId, nsAString& aGUID) -{ - NS_ENSURE_ARG_MIN(aItemId, 1); - - nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService(); - NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY); - nsresult rv = annosvc->GetItemAnnotationString(aItemId, GUID_ANNO, aGUID); - if (NS_SUCCEEDED(rv) || rv != NS_ERROR_NOT_AVAILABLE) - return rv; - - nsAutoString tmp; - tmp.AppendInt(mItemCount++); - aGUID.SetCapacity(NSID_LENGTH - 1 + tmp.Length()); - nsString GUIDBase; - rv = GetGUIDBase(GUIDBase); - NS_ENSURE_SUCCESS(rv, rv); - aGUID.Assign(GUIDBase); - aGUID.Append(tmp); - - rv = SetItemGUID(aItemId, aGUID); - NS_ENSURE_SUCCESS(rv, rv); - return NS_OK; -} - - -NS_IMETHODIMP -nsNavBookmarks::SetItemGUID(PRInt64 aItemId, const nsAString& aGUID) -{ - NS_ENSURE_ARG_MIN(aItemId, 1); - - PRInt64 checkId; - GetItemIdForGUID(aGUID, &checkId); - if (checkId != -1) - return NS_ERROR_INVALID_ARG; // invalid GUID, already exists - - nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService(); - NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY); - nsresult rv = annosvc->SetItemAnnotationString(aItemId, GUID_ANNO, aGUID, 0, - nsIAnnotationService::EXPIRE_NEVER); - NS_ENSURE_SUCCESS(rv, rv); - return NS_OK; -} - - -NS_IMETHODIMP -nsNavBookmarks::GetItemIdForGUID(const nsAString& aGUID, PRInt64* aItemId) -{ - NS_ENSURE_ARG_POINTER(aItemId); - - nsCOMPtr stmt = mDB->GetStatement( - "SELECT item_id FROM moz_items_annos " - "WHERE content = :guid " - "LIMIT 1" - ); - NS_ENSURE_STATE(stmt); - mozStorageStatementScoper scoper(stmt); - - nsresult rv = stmt->BindStringByName(NS_LITERAL_CSTRING("guid"), aGUID); - NS_ENSURE_SUCCESS(rv, rv); - - bool hasMore = false; - rv = stmt->ExecuteStep(&hasMore); - if (NS_FAILED(rv) || ! hasMore) { - *aItemId = -1; - return NS_OK; // not found: return -1 - } - - // found, get the itemId - rv = stmt->GetInt64(0, aItemId); - NS_ENSURE_SUCCESS(rv, rv); - return NS_OK; -} - - NS_IMETHODIMP nsNavBookmarks::SetItemTitle(PRInt64 aItemId, const nsACString& aTitle) { diff --git a/toolkit/components/places/nsNavBookmarks.h b/toolkit/components/places/nsNavBookmarks.h index 01f4073d3b63..6324455f3e9d 100644 --- a/toolkit/components/places/nsNavBookmarks.h +++ b/toolkit/components/places/nsNavBookmarks.h @@ -308,9 +308,6 @@ private: */ nsRefPtr mDB; - nsString mGUIDBase; - nsresult GetGUIDBase(nsAString& aGUIDBase); - PRInt32 mItemCount; nsMaybeWeakPtrArray mObservers; diff --git a/toolkit/components/places/tests/bookmarks/test_360134.js b/toolkit/components/places/tests/bookmarks/test_360134.js deleted file mode 100644 index d220bfc0238a..000000000000 --- a/toolkit/components/places/tests/bookmarks/test_360134.js +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Bug 360134 (item guids) unit test code. - * - * The Initial Developer of the Original Code is Mozilla Foundation. - * Portions created by the Initial Developer are Copyright (C) 2007 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Dan Mills - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -// Get bookmark service -try { - var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); -} catch(ex) { - do_throw("Could not get nav-bookmarks-service\n"); -} - -// main -function run_test() { - var URI = uri("http://foo.tld.com/"); - var folderId = bmsvc.createFolder(bmsvc.placesRoot, "test folder", - bmsvc.DEFAULT_INDEX); - var bookmarkId = bmsvc.insertBookmark(folderId, URI, bmsvc.DEFAULT_INDEX, "a title"); - var separatorId = bmsvc.insertSeparator(folderId, bmsvc.DEFAULT_INDEX); - - // get & uniqueness - do_check_eq(bmsvc.getItemGUID(bookmarkId), bmsvc.getItemGUID(bookmarkId)); - - do_check_neq(bmsvc.getItemGUID(folderId), bmsvc.getItemGUID(bookmarkId)); - do_check_neq(bmsvc.getItemGUID(folderId), ""); - - do_check_neq(bmsvc.getItemGUID(separatorId), bmsvc.getItemGUID(bookmarkId)); - do_check_neq(bmsvc.getItemGUID(separatorId), ""); - - // set - bmsvc.setItemGUID(bookmarkId, "asdf123"); - do_check_eq(bmsvc.getItemGUID(bookmarkId), "asdf123"); - - bmsvc.setItemGUID(folderId, "123asdf"); - do_check_eq(bmsvc.getItemGUID(folderId), "123asdf"); - - try { - bmsvc.setItemGUID(bookmarkId, "123asdf"); // should fail - } catch (e) { - do_check_eq(e.result, Cr.NS_ERROR_ILLEGAL_VALUE); - } - - // GUID -> itemId - do_check_eq(bmsvc.getItemIdForGUID("asdf123"), bookmarkId); - do_check_eq(bmsvc.getItemIdForGUID("123asdf"), folderId); - -} diff --git a/toolkit/components/places/tests/bookmarks/test_484026.js b/toolkit/components/places/tests/bookmarks/test_484026.js deleted file mode 100644 index f04dc5172c05..000000000000 --- a/toolkit/components/places/tests/bookmarks/test_484026.js +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Places Unit Test Code. - * - * The Initial Developer of the Original Code is Mozilla Foundation. - * Portions created by the Initial Developer are Copyright (C) 2009 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Saint Wesonga - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); - -function testThrowsOnDeletedItemId(aItemId) { - try { - bmsvc.getItemGUID(aItemId); - do_throw("getItemGUID should throw when called for a deleted item id"); - } catch (e) { - do_check_eq(e.result, Cr.NS_ERROR_ILLEGAL_VALUE); - } -} - -function run_test() { - var folderId = bmsvc.createFolder(bmsvc.placesRoot, "test folder", - bmsvc.DEFAULT_INDEX); - var bookmarkId = bmsvc.insertBookmark(folderId, uri("http://foo.tld.com/"), - bmsvc.DEFAULT_INDEX, "a title"); - var separatorId = bmsvc.insertSeparator(folderId, bmsvc.DEFAULT_INDEX); - - bmsvc.removeItem(folderId); - - // getItemGUID should throw when called for a deleted item id - [folderId, bookmarkId, separatorId].forEach(testThrowsOnDeletedItemId); -} diff --git a/toolkit/components/places/tests/bookmarks/test_restore_guids.js b/toolkit/components/places/tests/bookmarks/test_restore_guids.js deleted file mode 100644 index 30d801de98e6..000000000000 --- a/toolkit/components/places/tests/bookmarks/test_restore_guids.js +++ /dev/null @@ -1,118 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set ts=2 sw=2 sts=2 et: */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Bug 384370 code. - * - * The Initial Developer of the Original Code is the Mozilla Foundation. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Dietrich Ayala (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -var tests = []; - -/* - -Backup/restore tests example: - -var myTest = { - populate: function () { ... add bookmarks ... }, - validate: function () { ... query for your bookmarks ... } -} - -this.push(myTest); - -*/ - -const DEFAULT_INDEX = PlacesUtils.bookmarks.DEFAULT_INDEX; - -var test = { - _testBookmarkId: null, - _testBookmarkGUID: null, - - populate: function populate() { - var bookmarkURI = uri("http://bookmark"); - this._testBookmarkId = - PlacesUtils.bookmarks.insertBookmark(PlacesUtils.toolbarFolderId, bookmarkURI, - DEFAULT_INDEX, "bookmark"); - this._testBookmarkGUID = PlacesUtils.bookmarks.getItemGUID(this._testBookmarkId); - }, - - clean: function () {}, - - validate: function validate() { - var guid = PlacesUtils.bookmarks.getItemGUID(this._testBookmarkId); - do_check_eq(this._testBookmarkGUID, guid); - } -} -tests.push(test); - -function run_test() { - do_check_eq(typeof PlacesUtils, "object"); - - // make json file - var jsonFile = Services.dirsvc.get("ProfD", Ci.nsILocalFile); - jsonFile.append("bookmarks.json"); - if (jsonFile.exists()) - jsonFile.remove(false); - jsonFile.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, 0600); - if (!jsonFile.exists()) - do_throw("couldn't create file: bookmarks.exported.json"); - - // populate db - tests.forEach(function(aTest) { - aTest.populate(); - // sanity - aTest.validate(); - }); - - // export json to file - try { - PlacesUtils.backups.saveBookmarksToJSONFile(jsonFile); - } catch(ex) { do_throw("couldn't export to file: " + ex); } - - // clean - tests.forEach(function(aTest) { - aTest.clean(); - }); - - // restore json file - try { - PlacesUtils.restoreBookmarksFromJSONFile(jsonFile); - } catch(ex) { do_throw("couldn't import the exported file: " + ex); } - - // validate - tests.forEach(function(aTest) { - aTest.validate(); - }); - - // clean up - jsonFile.remove(false); -} diff --git a/toolkit/components/places/tests/bookmarks/xpcshell.ini b/toolkit/components/places/tests/bookmarks/xpcshell.ini index 56bd7ca73698..e37d2f37b5a3 100644 --- a/toolkit/components/places/tests/bookmarks/xpcshell.ini +++ b/toolkit/components/places/tests/bookmarks/xpcshell.ini @@ -2,7 +2,6 @@ head = head_bookmarks.js tail = -[test_360134.js] [test_384228.js] [test_385829.js] [test_388695.js] @@ -18,7 +17,6 @@ tail = [test_458683.js] [test_466303-json-remove-backups.js] [test_477583_json-backup-in-future.js] -[test_484026.js] [test_async_observers.js] [test_bmindex.js] [test_bookmarks.js] @@ -29,7 +27,6 @@ tail = [test_nsINavBookmarkObserver.js] [test_onBeforeItemRemoved_observer.js] [test_removeItem.js] -[test_restore_guids.js] [test_savedsearches.js] [test_675416.js] [test_711914.js] diff --git a/toolkit/components/places/tests/head_common.js b/toolkit/components/places/tests/head_common.js index 33b0d76fe2cf..cca307d39db9 100644 --- a/toolkit/components/places/tests/head_common.js +++ b/toolkit/components/places/tests/head_common.js @@ -35,7 +35,7 @@ * * ***** END LICENSE BLOCK ***** */ -const CURRENT_SCHEMA_VERSION = 19; +const CURRENT_SCHEMA_VERSION = 20; const NS_APP_USER_PROFILE_50_DIR = "ProfD"; const NS_APP_PROFILE_DIR_STARTUP = "ProfDS"; diff --git a/toolkit/components/places/tests/migration/places_v19.sqlite b/toolkit/components/places/tests/migration/places_v19.sqlite new file mode 100644 index 0000000000000000000000000000000000000000..11e2e6247ba85f31d64cd59f3c1bc5d0e3d6be4e GIT binary patch literal 1179648 zcmeI*d30QNeJJqRw2WfK2_Yy8kO_&MxUnoL@|J`&kz>VCEZeayujCvtmd5hfBaJ*W zTI|HWwgcxSl(r-(rFn&tK3eF3K;aPDv@wO&VJl0arDY3Y3kTX7QlJ4Iq~zV1kz~nR z!tzc@`nf*(-TPa=zu)Kn?#z|{(fYOB*-|F8Jzp41ms0JK1CdxPa(yZliA3Vz&!yqd z&(ZMboN4)!UB)BLU%#Yr-(!(Wa$6$%AK3Tx+aKTerrT%V{+_)***kCV zd-oLf{KuZu_@eP|jlE**yQ7Vzca_q`?-zfocv0cqh1T7_zx%A=*9)d>#g(tVk!rZX!qIn~@w*>!SSl?JKHD}$eE zMzM?Qnz}BF9=v!e=(c=**I>G^tJpg*lI`yu8OrV+Ifgb>`?6C_YpTTw{U_%&)gpCy zImEotR9({z7e^1CJ2i*Olutf^YSqQ3ihhcolcB5C6LE_d)irg5anC+J?nohb{JJMP zK10~!IvyW2te$u9?3dOxtq;W)O+}sZsBF|+x>y>__h+|fGyNwvxoBbr$F}G*^q!o< zRI}9O+jq@Rm7}bhh%#^AOX`}gJH;j#P8Tvmr4uLe($h?2TA!1Iuhz~_4d;v5QZ_#{ zZ}*Gqnyv}MH=Y=!B64E!OHLEK{QOmVoFsI4<)uBtnRy4}7lwPTW%|C~ku8?;g*~I$ za8||M{`9m@iWyZeJ|Xsu>SH}8 zWzMZ@S`@~L9=C+v9r@z1r@gw|7o959RNLbt6*8lhf#waqFnqMbFlQVeW_x-x+m|0Y zuK3(jMVj9H_+S%t_DGw;x?FQ{v};)>|2@|EF^dmT6~d(MnOkE={wo=Ro=!`F(Q&J~^O zQn#$@TGg>`OKN53mieiP*M+Id)oXfEt2cCapXB{vvd#R|V0JLmTmB$RZR}Wg!%ZFQ zE^ohbUTS&gjU5}hC%cEbrSOwG)xBo*iiuY9Q`>Xtf#T#iQyp68r!wQi*+RPfaeT7c zN~p={PlgG5l^?&3{{GCdwN0y>{uOiLpz{u`JiD&xqKl%h%1rU5%WrFCyUN82P9Uum zpANIKU&DIFPpxd?iLWea^7_mZ z)-qXhxf(`+K!IAgiTwY|K2Z{`;>yXW2BP_a9B z&6M4)%$~7)p}%4`d40x=!OAybvgXuwsg4ajYr0m4Jy&(E?wOyO=ur`vV4Sz)jAw$F zj8lb}%*{GjS6|)Di>Bs1_5Rvh$mdIy=^s~=JYf~bH7GBp+_`tg)@@rnZ|b&h&*%Cx zg=rrk^E#8yw26-kQeDY$g$;*ZP*>M<*=5l?`c7O>*?X#e{izpm>U&Xrsh#}L3qR#| zOTSys!)~hh4P+1$ydS5-!YCwIQEfr=rR~^M%F{pbyJE_$bzWO- zZByq(r+bns6RO_x%4OZb#qqkP=H}?3i>4Np9U2}fO}tWB_5A8KUIC{Ex)K7YgH|q{!%kP zRm>EN)82mO9a)$;PBPx-!g+&516=$`n*O};)) zzqOMqnQ>2#ZPody9og_j>?Ch*)Aq#7{XX@oHm$|PSJBL8{kZ35Drj@tw4TTP?lg&= zn*PPu7;ce<+m}Uxw*_nWKe_+D{ayQO_7(Rnx&0Gip@RSc0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB=D?Q{Z4-!>q_{UCqh*`e?Lv&W=)P`0AFHv9YlQ;h$yC=5px; z`NBZUa3Q}l(^o3CY|j=l+wO=Z)avZOj#6$q!D_qJ?uR%BnKJdw!H zF_E@~3tH1{<#`oLg^{6_<6~7rJ$UE7%+}V$t2-90+|tvYy}Eu@WNjo;pRAA6N9I)i z#{AXgKjnVy;%EA!nuR#@pYNvNUl`8wykw|b$b2g?ll8DHZEU!aCTi|KnVdJD2xP)lOFQtXb2&tYh8W-6NU8 zo}Tgq+9oD&<;)4p&5ZZuM*1^r!-m;RIHh!9No(uw(GA;oEgf1`J1detZa#%fe|Ss6 zJGLs{pSkwR>ZnU+4!UW4+0N!=8&`Dqjt{J^nH56_SHS%mn?aK_63hCTQ2HvsrrX|IVnQa68 z8&@@kPkSu*LL~T3m^cU!AV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!CvW zP2dHwx=1ow8;v$Z5{Hl6`p^YOYh!0e>mv2h+GI3YDSPnFeX+*!x(__x7H>TS2oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkL{=M!isH$U+6_0gID0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&=-vk=N1;v6dM1rGX;vhhP009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RqoAfwN;ZkxQcWgZaJLTrRyJUl{0rK{PCi zO%?U!2P3a-2-h78z7`3-7bXq@1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNCfd=;1-za%=C-{xW>tVl8% zOB|h2Qa$N`Vzv3%ORMK|?^vD5_hd(w@7l3taOt&;m2UOzm2Pzt-EwD>9{2*U)G_H#!;Z+`ekZxm#}>-#gGfklws;WNYs= z$x6p$OC?&o?uLl!>RO8f2wDslrLn{x$2zn{>PV8M|u218&@tFFYO%IlU=mB`RcmrJ-njY zI~EF6{!abO$bWZFHFE1Cn~H^n3-jy7HjS>_ytFoqoQx)`edFP3OWC1;)cR7oFv)xO zgH6?_55Il&XlHMBthBOy&CQ!%UQ>>mj84oszG0}CFZY?ctJOKb`t=W0dv|rMDeW35 zEy{K--8e9|AW`jo?!=s@_RwVe@VvI?rjgAZJ2G2#4ri~9SK3eT#wK@8G1ZgL=eDH_ zl^BzK!wr$ynJ;Gg220(0_Kq)!Rr=P?tHwIkcU5L+WJbqu-#4#Z*L>C5RfU1{q8sK# z%N^_M8><~>G!0{|>{z;X_f@N|>Rz#OZ`dSK6MQ5RJQ@6Z@L2HK@X|qm009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjY`s{&`##4n7F3~kTmGW|96iTJtEQhK16 zI3pewm-6}Cwsaw09}9~IGeaY>WHf$$ayXan%M=^J71soxhy*_hz7sqid_KH%5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7csf#xlDge`MQ+P z=eDH_@%s3=(NcP#m`KLYPY&nOeVJmpXfQK05^F54_`q{|*(Ohb009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjYmX@Q3F2nT-YVGKZk009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjY`(*lj<*&ldLFTvyq5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7e?FD=j*j!;wlXk_2!z3(2cA9-bX=^#LW009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBly@VpbayuIgdum0-Oe|XQ)yJHt72bLcG(ATd2 z*FS&9`)<7XuGigJzjfDtKDOtI!(Vw~dE(;tbj|u!GNr~eRXzb1P0O@DdbyWjE1TT|cazWJ`suXjGW^~fhSk4Ap--P;fR!B;ac zt^44YKXSC~rJp<$AMGzZ+WgbaZ@c4L-)&D_`skb9_=C6HTc3F2u2;s+js9nw=Q_q@=x8j^@`s* zRR5lLEqUo*eEPQFJ%6+6FTV1#N48$^y*J)|v@2Nm{;_Sd2fq79#h=Y;z2kTOB8lYuKSbFDALurdilGSz4B0YFg=iI86FylB;J2Z^Mgvk+ZQfe(zbZvq9yIm z;%-F}10Ab6B9TA;=#rY({A)PB^GltZOY8I7OJnImCeqQL-rgEuRq*y=M%Br7o7F* z_1}B@hIfqq?Prg)ULQGl*M02+zgc_153hUS+s|J9hWPh_zWTElU`s4E> zXI($*)2%z6$>G^_2Eb3dEvKeDmoNbTIeY52G1 z1Cc|2_0=DBFKm3`bwB>_D_a^4y+3+RU0rMIr=zhu&wf01%Y$u?KKzkSM;A7JJ6F3Y zRr}X>{_%@1Sby&Ix4-D`7cXcT82`Y)>^naGh4;?7?ZE8^BC&@f-+uFVQWsu*|6AXD z@QaT|KlJVc-#PG;4;()H)OB~f;B{~M{U2VGI&j`&@4xLMXZ}u2$MV$ARutZP|NUPL z=G<~1_NLkYxb&R!F8S~W-yQ3`_M=ZmqKV(Fx#iFP`uf2=|LgG=^!?dyr+(|x{}ic@ zC(e3fblu~J`mg!u{r7$Nb+7yIpPv7!XsrH^nhtzy{71Ll|D}yL{NMXOc+Y*87sF1FhYOJ%1X%;Pv+(sHu73f-iNP7fxZ`CqEU5)<$Ms_In@s;I5C&KlMHx z`TWOsZo6T3v3TR^y@NL`di9+6FSJjuoW4&NFSSqY(_isEJ@TrKy+g~kELwI`S0+FF z>N&ArXrH!C-=~YNvQO>PU-3SD%R8^i-_ka|_J$jmuiduu)pMf1&^~RQu}@p=Q~UH+ zyiX4#M!QSf#&)!iw{>s3q5S?|v;Q9>!3TpN_|5(Q6<#_B5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAVA=GA@CdVEzupN((u(SEn{P23kLIhv$yZVJkhD8y}7Nuy?x=rC2flrE?Ux___+tT za{2&^m&SkY0otYyu;{ATb>R|{r&#Vum(V(6fY!$Fp2vd+BEgq~N5YeX009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF{Mrk=C?1cr59iW-nPS&aDN`6q=UP^5 z=vv+si$@mSQYmj)KbS6*mgV!i!t<_+qwz@Bwu#Iwh5T@)P|9YCE&Z8dUm-hO%I1d} z!d1tEcSeG51s@7e4gv%S5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAn@xi z&=hZv4(HN+nPS&aDN`6q=UP^5=vp4XINp`qme21ROc!?DQpgWy3Z-nO*wUXV_7$?j zrEGray!fK%EtQ@v>%&&1WfQGqjpbDz`1N1984@5sfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+0D=FX0*&F|HT%CD34Slw5iANC!b=AM0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PDCe1g@w#BNB~9=F~@{wY9bJ)uWxg*|E~f_BA(ePQ)XL z!$)qt_k|yvIDc$jqSE-{O5-zQ>oR?rp;AwJpm<`_ws@s!Tcv5^MAO`!W%>NB!E|9) zrhl?a!v)pR8(#Jsu}YUqDqUv9R^^MOjoD(hG}ZQ=pFL7(d(Y24xidN|5=}-9RvX7V z`ukJcCWbDiO8Hc2N4A*Sp3n7X3gv7ulL?D5gQ@;(aX6RWlj%?8hsq_X$q5xxJ^6fY zTe>hYue;yyg-Wcu-|+Ru@SZ1vwn*@a;O^j+;e~?$0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&=8-eCT;<9U+2J?G+x8?J@2GfOI#Tl92Y$-FC9qP}FFG_{~ zTH=Yzt~*`x;dCK0RGR3}o@%=)mbh&F={l6h&!vl{!F+#qdp6U5EY_9L#ARLQ%$UuL zOz*%*w!e2|D7$+kGtsN9AzX7q@bO6SRPdwV`@wgDZwKE9z8rim_)J*nAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0?$2xns_u?(@;(mHRUv(D5tS_BA$%K z67fhhSx)N9NnJUqjmIO&hH#w?L2o4ZY4F3~d%>f@M}qeTe-zvml)^#>0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U_|*u!Fy0&;%=axw=W^M-`N0KaV`B?y zPF9#WSz-KSg|Tzu&B^1(EH@k|A8UkE-M7CHzJAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!Ct= zQy>vfMjOgWG7+zj)|ZpIa#CAPYRXBXoW#pXEFP~W z!RLd|1b-hEItUOTK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfWUJ{pf(XfnM7%y)Ury@ENo_;8&W7Lvk>IJ|N5S`l?*!it zz7aeYd?ENmSm+=?fB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009Ee4S`wl z+Gr$k_{gmfU2wEvD)Zo-`;v)xBwAli>dHxNIjJcpiE_hjbS#KtYja&b6-Qa?pW}nNbppcI0z6RK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfWZGOfkZqRjm6{j$%b&r6sxaEB$LtF z+C(H8jnA%}Vs+J1P4$$hp5oP0tR`%kj5UO-n;pC%68toHGI%2RcJQ^}i@`qy9}kWM zhlBS8?+V@)yg96P5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7csf&UJH zx@^$CsALn>?A)ylm2AA4tzVF=WMh@= z-H(5$zA=%kjaG9HzrD6G5t+!{d;VRsXXIkXa`*h?f%vps>mzl?a(8!i)f~&c`t=Vb zW`$!WD-pt6L%6zzeIJShpAX&^6oc!6v-bbf{x|HuaNp6e&_RFz0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5;&=bFIW_}b`jF5Q>8y0m9FbM4}}#eAW3ZQH`RgX!^g znc_&URJ^vWwSGZ7J<+U?>CYB2eWl{6e1GQJE3567&TL+LTjJoJiT2y`x&BPy+GT6j ztX$QxZsq#kRh_Fh%$+FRu=>WX?#|`CQ?-*7J!{r{N8LXmtK%B473av@;l2@Z`mF$ zVS9c&EXWixxlFp4S+Jutm}_`>eBZO~+qQ5)Yr3sGRIyYT8EQ$EjZPA{FF)9l8EW3J zek$sYOm4U()*j#W?3(wD6ifNR?A}aE{Mq-(4-SqDWlMWn60Pxp<9}T1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZ;Fl9PD?TSW);qdm!;X;+ecMWVYsv+s(fq)! zTbMbP)=CN$PxM<0y8{4|KHIxfB zjW65Tylmr&?%wf%+H%2_+qQOR$9Jvj?P&7;XuH0N#F4(wo$#`k!z@F@))y?(gg0($2jco4N zk=e3yIGZRJtSRjpDJ{x&F5NgVR#Pe1G&<0I^YWdG*R1K8RW4XP+S!{OE3Ir_bMxlf zNO$xiJ>6oM**im2+*prX~?h HCgcAPwr3cg literal 0 HcmV?d00001 diff --git a/toolkit/components/places/tests/migration/test_current_from_v19.js b/toolkit/components/places/tests/migration/test_current_from_v19.js new file mode 100644 index 000000000000..170d7c6e6b35 --- /dev/null +++ b/toolkit/components/places/tests/migration/test_current_from_v19.js @@ -0,0 +1,62 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * This file tests migration invariants from schema version 19 to the current + * schema version. + */ + +//////////////////////////////////////////////////////////////////////////////// +//// Globals + +const kGuidAnnotationName = "placesInternal/GUID"; + +function getTotalGuidAnnotationsCount(aStorageConnection) { + stmt = aStorageConnection.createStatement( + "SELECT count(*) " + + "FROM moz_items_annos a " + + "JOIN moz_anno_attributes b ON a.anno_attribute_id = b.id " + + "WHERE b.name = :attr_name" + ); + try { + stmt.params.attr_name = kGuidAnnotationName; + do_check_true(stmt.executeStep()); + return stmt.getInt32(0); + } finally { + stmt.finalize(); + } +} + +//////////////////////////////////////////////////////////////////////////////// +//// Tests + +function run_test() +{ + setPlacesDatabase("places_v19.sqlite"); + run_next_test(); +} + +add_test(function test_initial_state() +{ + let dbFile = gProfD.clone(); + dbFile.append(kDBName); + let db = Services.storage.openUnsharedDatabase(dbFile); + + // There should be an obsolete bookmark GUID annotation. + do_check_eq(getTotalGuidAnnotationsCount(db), 1); + + // Check our schema version to make sure it is actually at 19. + do_check_eq(db.schemaVersion, 19); + + db.close(); + run_next_test(); +}); + +add_test(function test_bookmark_guid_annotation_removed() +{ + + // There should be no obsolete bookmark GUID annotation anymore. + do_check_eq(getTotalGuidAnnotationsCount(DBConn()), 0); + + run_next_test(); +}); diff --git a/toolkit/components/places/tests/migration/xpcshell.ini b/toolkit/components/places/tests/migration/xpcshell.ini index 6722a8be386d..19bacd69d9d7 100644 --- a/toolkit/components/places/tests/migration/xpcshell.ini +++ b/toolkit/components/places/tests/migration/xpcshell.ini @@ -4,6 +4,7 @@ tail = [test_current_from_v10.js] [test_current_from_v10_migrated_from_v14.js] +[test_current_from_v19.js] [test_database_from_alpha.js] [test_database_from_v6_no_frecency.js] [test_database_from_v6_no_indices.js] diff --git a/toolkit/components/places/tests/unit/test_null_interfaces.js b/toolkit/components/places/tests/unit/test_null_interfaces.js index f40efb9d1f95..2e26ad6ba811 100644 --- a/toolkit/components/places/tests/unit/test_null_interfaces.js +++ b/toolkit/components/places/tests/unit/test_null_interfaces.js @@ -54,7 +54,7 @@ let testServices = [ ["queryStringToQueries", "removePagesByTimeframe", "removePagesFromHost", "removeVisitsByTimeframe"]], ["browser/nav-bookmarks-service;1","nsINavBookmarksService", - ["createFolder", "getItemIdForGUID"]], + ["createFolder"]], ["browser/livemark-service;2","nsILivemarkService", []], ["browser/livemark-service;2","mozIAsyncLivemarks", ["reloadLivemarks"]], ["browser/annotation-service;1","nsIAnnotationService", []], diff --git a/toolkit/components/places/tests/unit/test_preventive_maintenance.js b/toolkit/components/places/tests/unit/test_preventive_maintenance.js index ed5785c813c1..26a514d89f09 100644 --- a/toolkit/components/places/tests/unit/test_preventive_maintenance.js +++ b/toolkit/components/places/tests/unit/test_preventive_maintenance.js @@ -108,6 +108,99 @@ let current_test = null; //------------------------------------------------------------------------------ +tests.push({ + name: "A.1", + desc: "Remove obsolete annotations from moz_annos", + + _obsoleteWeaveAttribute: "weave/test", + _placeId: null, + + setup: function() { + // Add a place to ensure place_id = 1 is valid. + this._placeId = addPlace(); + // Add an obsolete attribute. + let stmt = mDBConn.createStatement( + "INSERT INTO moz_anno_attributes (name) VALUES (:anno)" + ); + stmt.params['anno'] = this._obsoleteWeaveAttribute; + stmt.execute(); + stmt.finalize(); + stmt = mDBConn.createStatement( + "INSERT INTO moz_annos (place_id, anno_attribute_id) " + + "VALUES (:place_id, " + + "(SELECT id FROM moz_anno_attributes WHERE name = :anno)" + + ")" + ); + stmt.params['place_id'] = this._placeId; + stmt.params['anno'] = this._obsoleteWeaveAttribute; + stmt.execute(); + stmt.finalize(); + }, + + check: function() { + // Check that the obsolete annotation has been removed. + let stmt = mDBConn.createStatement( + "SELECT id FROM moz_anno_attributes WHERE name = :anno" + ); + stmt.params['anno'] = this._obsoleteWeaveAttribute; + do_check_false(stmt.executeStep()); + stmt.finalize(); + } +}); + +tests.push({ + name: "A.2", + desc: "Remove obsolete annotations from moz_items_annos", + + _obsoleteSyncAttribute: "sync/children", + _obsoleteGuidAttribute: "placesInternal/GUID", + _obsoleteWeaveAttribute: "weave/test", + _placeId: null, + _bookmarkId: null, + + setup: function() { + // Add a place to ensure place_id = 1 is valid. + this._placeId = addPlace(); + // Add a bookmark. + this._bookmarkId = addBookmark(this._placeId); + // Add an obsolete attribute. + let stmt = mDBConn.createStatement( + "INSERT INTO moz_anno_attributes (name) " + + "VALUES (:anno1), (:anno2), (:anno3)" + ); + stmt.params['anno1'] = this._obsoleteSyncAttribute; + stmt.params['anno2'] = this._obsoleteGuidAttribute; + stmt.params['anno3'] = this._obsoleteWeaveAttribute; + stmt.execute(); + stmt.finalize(); + stmt = mDBConn.createStatement( + "INSERT INTO moz_items_annos (item_id, anno_attribute_id) " + + "SELECT :item_id, id " + + "FROM moz_anno_attributes " + + "WHERE name IN (:anno1, :anno2, :anno3)" + ); + stmt.params['item_id'] = this._bookmarkId; + stmt.params['anno1'] = this._obsoleteSyncAttribute; + stmt.params['anno2'] = this._obsoleteGuidAttribute; + stmt.params['anno3'] = this._obsoleteWeaveAttribute; + stmt.execute(); + stmt.finalize(); + }, + + check: function() { + // Check that the obsolete annotations have been removed. + let stmt = mDBConn.createStatement( + "SELECT id FROM moz_anno_attributes " + + "WHERE name IN (:anno1, :anno2, :anno3)" + ); + stmt.params['anno1'] = this._obsoleteSyncAttribute; + stmt.params['anno2'] = this._obsoleteGuidAttribute; + stmt.params['anno3'] = this._obsoleteWeaveAttribute; + do_check_false(stmt.executeStep()); + stmt.finalize(); + } +}); + tests.push({ name: "A.3", desc: "Remove unused attributes", diff --git a/toolkit/components/places/tests/unit/test_txnGUIDs.js b/toolkit/components/places/tests/unit/test_txnGUIDs.js deleted file mode 100644 index d5188d9c1312..000000000000 --- a/toolkit/components/places/tests/unit/test_txnGUIDs.js +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Mozilla Foundation. - * Portions created by the Initial Developer are Copyright (C) 2009 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Marco Bonardo - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * This test will ensure any transactions service that is going to create - * a new item, won't replace the GUID when undoing and redoing the action. - */ - -function test_GUID_persistance(aTxn) { - aTxn.doTransaction(); - waitForAsyncUpdates(function () { - let itemId = PlacesUtils.bookmarks - .getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0); - let GUID = PlacesUtils.bookmarks.getItemGUID(itemId); - aTxn.undoTransaction(); - aTxn.redoTransaction(); - waitForAsyncUpdates(function() { - let itemId = PlacesUtils.bookmarks - .getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0); - do_check_eq(GUID, PlacesUtils.bookmarks.getItemGUID(itemId)); - aTxn.undoTransaction(); - waitForAsyncUpdates(run_next_test); - }); - }); -} - -function run_test() { - run_next_test(); -} - -add_test(function create_folder() { - let createFolderTxn = new PlacesCreateFolderTransaction( - "Test folder", PlacesUtils.unfiledBookmarksFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX - ); - test_GUID_persistance(createFolderTxn); -}); - -add_test(function create_bookmark() { - let createBookmarkTxn = new PlacesCreateBookmarkTransaction( - NetUtil.newURI("http://www.example.com"), PlacesUtils.unfiledBookmarksFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX, "Test bookmark" - ); - test_GUID_persistance(createBookmarkTxn); -}); - -add_test(function create_separator() { - let createSeparatorTxn = new PlacesCreateSeparatorTransaction( - PlacesUtils.unfiledBookmarksFolderId, PlacesUtils.bookmarks.DEFAULT_INDEX - ); - test_GUID_persistance(createSeparatorTxn); -}); - -add_test(function tag_uri() { - let tagURITxn = new PlacesTagURITransaction( - NetUtil.newURI("http://www.example.com"), ["foo"] - ); - test_GUID_persistance(tagURITxn); -}); - -add_test(function create_livemark() { - let createLivemarkTxn = new PlacesCreateLivemarkTransaction( - NetUtil.newURI("http://feeduri.com"), NetUtil.newURI("http://siteuri.com"), - "Test livemark", PlacesUtils.unfiledBookmarksFolderId, - PlacesUtils.bookmarks.DEFAULT_INDEX - ); - test_GUID_persistance(createLivemarkTxn); -}); - diff --git a/toolkit/components/places/tests/unit/xpcshell.ini b/toolkit/components/places/tests/unit/xpcshell.ini index 1fb05f75418d..50d69362e147 100644 --- a/toolkit/components/places/tests/unit/xpcshell.ini +++ b/toolkit/components/places/tests/unit/xpcshell.ini @@ -116,5 +116,4 @@ skip-if = os == "android" [test_PlacesUtils_asyncGetBookmarkIds.js] [test_PlacesUtils_lazyobservers.js] [test_placesTxn.js] -[test_txnGUIDs.js] [test_telemetry.js] From 692998f4d8cbd188d979a812d86f3de492cd177c Mon Sep 17 00:00:00 2001 From: Paolo Amadini Date: Thu, 12 Apr 2012 12:28:12 +0200 Subject: [PATCH 09/14] Bug 742714 - Remove LMANNO_EXPIRATION, LMANNO_LOADFAILED, and LMANNO_LOADING. r=mak --HG-- extra : rebase_source : df909400325dc84602964b9d2073cdacb06eeffb --- toolkit/components/places/PlacesUtils.jsm | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/toolkit/components/places/PlacesUtils.jsm b/toolkit/components/places/PlacesUtils.jsm index cc0b91854c6a..52df1399aae5 100644 --- a/toolkit/components/places/PlacesUtils.jsm +++ b/toolkit/components/places/PlacesUtils.jsm @@ -133,9 +133,6 @@ var PlacesUtils = { EXCLUDE_FROM_BACKUP_ANNO: "places/excludeFromBackup", LMANNO_FEEDURI: "livemark/feedURI", LMANNO_SITEURI: "livemark/siteURI", - LMANNO_EXPIRATION: "livemark/expiration", - LMANNO_LOADFAILED: "livemark/loadfailed", - LMANNO_LOADING: "livemark/loading", POST_DATA_ANNO: "bookmarkProperties/POSTData", READ_ONLY_ANNO: "placesInternal/READ_ONLY", @@ -1387,10 +1384,6 @@ var PlacesUtils = { case this.LMANNO_SITEURI: siteURI = this._uri(aAnno.value); return false; - case this.LMANNO_EXPIRATION: - case this.LMANNO_LOADING: - case this.LMANNO_LOADFAILED: - return false; default: return true; } @@ -2703,10 +2696,7 @@ function PlacesRemoveLivemarkTransaction(aLivemarkId) let annos = PlacesUtils.getAnnotationsForItem(this.item.id); // Exclude livemark service annotations, those will be recreated automatically let annosToExclude = [PlacesUtils.LMANNO_FEEDURI, - PlacesUtils.LMANNO_SITEURI, - PlacesUtils.LMANNO_EXPIRATION, - PlacesUtils.LMANNO_LOADFAILED, - PlacesUtils.LMANNO_LOADING]; + PlacesUtils.LMANNO_SITEURI]; this.item.annotations = annos.filter(function(aValue, aIndex, aArray) { return annosToExclude.indexOf(aValue.name) == -1; }); From 4c7593ce504afdeeade783dbbdd0049a7af5c2ee Mon Sep 17 00:00:00 2001 From: Asaf Romano Date: Thu, 12 Apr 2012 12:41:09 +0200 Subject: [PATCH 10/14] Bug 744189 - Can't open bookmarks from the Firefox button. r=mak --HG-- extra : rebase_source : 82a55f2c2c3336dd6357e05fd198a661a79b8540 --- browser/base/content/browser-appmenu.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser/base/content/browser-appmenu.inc b/browser/base/content/browser-appmenu.inc index b24281251adc..6d64185c3c39 100644 --- a/browser/base/content/browser-appmenu.inc +++ b/browser/base/content/browser-appmenu.inc @@ -270,8 +270,8 @@ placespopup="true" context="placesContext" openInTabs="children" - oncommand="BookmarksEventHandler.onCommand(event);" - onclick="BookmarksEventHandler.onClick(event);" + oncommand="BookmarksEventHandler.onCommand(event, this.parentNode._placesView);" + onclick="BookmarksEventHandler.onClick(event, this.parentNode._placesView);" onpopupshowing="BookmarksMenuButton.onPopupShowing(event); if (!this.parentNode._placesView) new PlacesMenu(event, 'place:folder=BOOKMARKS_MENU');" From bffb536c620b3d49e3136d0eecbd8e4d7ae50788 Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Thu, 12 Apr 2012 09:10:56 -0700 Subject: [PATCH 11/14] Bug 744794 - Remove password debugging code. r=trivial --- .../android/PasswordsRepositorySession.java | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/mobile/android/base/sync/repositories/android/PasswordsRepositorySession.java b/mobile/android/base/sync/repositories/android/PasswordsRepositorySession.java index 51fff716fc25..ece223877157 100644 --- a/mobile/android/base/sync/repositories/android/PasswordsRepositorySession.java +++ b/mobile/android/base/sync/repositories/android/PasswordsRepositorySession.java @@ -62,7 +62,6 @@ public class PasswordsRepositorySession extends this.passwordsHelper = new QueryHelper(context, BrowserContractHelpers.PASSWORDS_CONTENT_URI, LOG_TAG); this.deletedPasswordsHelper = new QueryHelper(context, BrowserContractHelpers.DELETED_PASSWORDS_CONTENT_URI, LOG_TAG); this.passwordsProvider = context.getContentResolver().acquireContentProviderClient(BrowserContract.PASSWORDS_AUTHORITY_URI); - dumpDbs(); } private static final String[] GUID_COLS = new String[] { Passwords.GUID }; @@ -709,29 +708,4 @@ public class PasswordsRepositorySession extends cv.put(BrowserContract.Passwords.TIMES_USED, rec.timesUsed); return cv; } - - private void dumpDbs() { - Cursor cursor = null; - try { - // Dump passwords. - Logger.debug(LOG_TAG, "passwordsProvider: "); - cursor = passwordsHelper.safeQuery(passwordsProvider, ".dumpDBs", getAllColumns(), dateModifiedWhere(0), null, null); - RepoUtils.dumpCursor(cursor); - cursor.close(); - - // Dump deleted passwords. - Logger.debug(LOG_TAG, "deletedPasswordsProvider: "); - cursor = deletedPasswordsHelper.safeQuery(passwordsProvider, ".dumpDBs", getAllDeletedColumns(), dateModifiedWhereDeleted(0), null, null); - RepoUtils.dumpCursor(cursor); - - } catch (NullCursorException e) { - Logger.debug(LOG_TAG, "NullCursor in dumping DBs."); - } catch (RemoteException e) { - Logger.debug(LOG_TAG, "RemoteException in dumping DBs."); - } finally { - if (cursor != null) { - cursor.close(); - } - } - } } From 50af044f63d52ccdc1c03d44736688be38d59e99 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Mon, 19 Mar 2012 12:21:05 -0400 Subject: [PATCH 12/14] Bug 614188 - Part 1: setup mfbt/double-conversion; r=Waldo --- .../add-mfbt-api-markers.patch | 109 ++++++++++++++++++ mfbt/double-conversion/update.sh | 16 +++ .../use-StandardInteger.patch | 29 +++++ 3 files changed, 154 insertions(+) create mode 100644 mfbt/double-conversion/add-mfbt-api-markers.patch create mode 100755 mfbt/double-conversion/update.sh create mode 100644 mfbt/double-conversion/use-StandardInteger.patch diff --git a/mfbt/double-conversion/add-mfbt-api-markers.patch b/mfbt/double-conversion/add-mfbt-api-markers.patch new file mode 100644 index 000000000000..d3cb1daa8747 --- /dev/null +++ b/mfbt/double-conversion/add-mfbt-api-markers.patch @@ -0,0 +1,109 @@ +diff --git a/mfbt/double-conversion/double-conversion.h b/mfbt/double-conversion/double-conversion.h +index f98edae..e536a01 100644 +--- a/mfbt/double-conversion/double-conversion.h ++++ b/mfbt/double-conversion/double-conversion.h +@@ -28,6 +28,7 @@ + #ifndef DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_ + #define DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_ + ++#include "mozilla/Types.h" + #include "utils.h" + + namespace double_conversion { +@@ -129,7 +130,7 @@ class DoubleToStringConverter { + } + + // Returns a converter following the EcmaScript specification. +- static const DoubleToStringConverter& EcmaScriptConverter(); ++ static MFBT_API(const DoubleToStringConverter&) EcmaScriptConverter(); + + // Computes the shortest string of digits that correctly represent the input + // number. Depending on decimal_in_shortest_low and decimal_in_shortest_high +@@ -154,12 +155,12 @@ class DoubleToStringConverter { + // Returns true if the conversion succeeds. The conversion always succeeds + // except when the input value is special and no infinity_symbol or + // nan_symbol has been given to the constructor. +- bool ToShortest(double value, StringBuilder* result_builder) const { ++ MFBT_API(bool) ToShortest(double value, StringBuilder* result_builder) const { + return ToShortestIeeeNumber(value, result_builder, SHORTEST); + } + + // Same as ToShortest, but for single-precision floats. +- bool ToShortestSingle(float value, StringBuilder* result_builder) const { ++ MFBT_API(bool) ToShortestSingle(float value, StringBuilder* result_builder) const { + return ToShortestIeeeNumber(value, result_builder, SHORTEST_SINGLE); + } + +@@ -197,7 +198,7 @@ class DoubleToStringConverter { + // The last two conditions imply that the result will never contain more than + // 1 + kMaxFixedDigitsBeforePoint + 1 + kMaxFixedDigitsAfterPoint characters + // (one additional character for the sign, and one for the decimal point). +- bool ToFixed(double value, ++ MFBT_API(bool) ToFixed(double value, + int requested_digits, + StringBuilder* result_builder) const; + +@@ -229,7 +230,7 @@ class DoubleToStringConverter { + // kMaxExponentialDigits + 8 characters (the sign, the digit before the + // decimal point, the decimal point, the exponent character, the + // exponent's sign, and at most 3 exponent digits). +- bool ToExponential(double value, ++ MFBT_API(bool) ToExponential(double value, + int requested_digits, + StringBuilder* result_builder) const; + +@@ -267,7 +268,7 @@ class DoubleToStringConverter { + // The last condition implies that the result will never contain more than + // kMaxPrecisionDigits + 7 characters (the sign, the decimal point, the + // exponent character, the exponent's sign, and at most 3 exponent digits). +- bool ToPrecision(double value, ++ MFBT_API(bool) ToPrecision(double value, + int precision, + StringBuilder* result_builder) const; + +@@ -292,7 +293,7 @@ class DoubleToStringConverter { + // kBase10MaximalLength. + // Note that DoubleToAscii null-terminates its input. So the given buffer + // should be at least kBase10MaximalLength + 1 characters long. +- static const int kBase10MaximalLength = 17; ++ static const MFBT_DATA(int) kBase10MaximalLength = 17; + + // Converts the given double 'v' to ascii. 'v' must not be NaN, +Infinity, or + // -Infinity. In SHORTEST_SINGLE-mode this restriction also applies to 'v' +@@ -332,7 +333,7 @@ class DoubleToStringConverter { + // terminating null-character when computing the maximal output size. + // The given length is only used in debug mode to ensure the buffer is big + // enough. +- static void DoubleToAscii(double v, ++ static MFBT_API(void) DoubleToAscii(double v, + DtoaMode mode, + int requested_digits, + char* buffer, +@@ -343,7 +344,7 @@ class DoubleToStringConverter { + + private: + // Implementation for ToShortest and ToShortestSingle. +- bool ToShortestIeeeNumber(double value, ++ MFBT_API(bool) ToShortestIeeeNumber(double value, + StringBuilder* result_builder, + DtoaMode mode) const; + +@@ -351,15 +352,15 @@ class DoubleToStringConverter { + // corresponding string using the configured infinity/nan-symbol. + // If either of them is NULL or the value is not special then the + // function returns false. +- bool HandleSpecialValues(double value, StringBuilder* result_builder) const; ++ MFBT_API(bool) HandleSpecialValues(double value, StringBuilder* result_builder) const; + // Constructs an exponential representation (i.e. 1.234e56). + // The given exponent assumes a decimal point after the first decimal digit. +- void CreateExponentialRepresentation(const char* decimal_digits, ++ MFBT_API(void) CreateExponentialRepresentation(const char* decimal_digits, + int length, + int exponent, + StringBuilder* result_builder) const; + // Creates a decimal representation (i.e 1234.5678). +- void CreateDecimalRepresentation(const char* decimal_digits, ++ MFBT_API(void) CreateDecimalRepresentation(const char* decimal_digits, + int length, + int decimal_point, + int digits_after_point, diff --git a/mfbt/double-conversion/update.sh b/mfbt/double-conversion/update.sh new file mode 100755 index 000000000000..5f56df9cc838 --- /dev/null +++ b/mfbt/double-conversion/update.sh @@ -0,0 +1,16 @@ +# Usage: ./update.sh +# +# Copies the needed files from a directory containing the original +# double-conversion source that we need. + +cp $1/LICENSE ./ +cp $1/README ./ + +# Includes +cp $1/src/*.h ./ + +# Source +cp $1/src/*.cc ./ + +patch -p3 < add-mfbt-api-markers.patch +patch -p3 < useStandardInteger.patch diff --git a/mfbt/double-conversion/use-StandardInteger.patch b/mfbt/double-conversion/use-StandardInteger.patch new file mode 100644 index 000000000000..6cd49b3bcec6 --- /dev/null +++ b/mfbt/double-conversion/use-StandardInteger.patch @@ -0,0 +1,29 @@ +diff --git a/mfbt/double-conversion/utils.h b/mfbt/double-conversion/utils.h +index cd3e330..bdc7d4b 100644 +--- a/mfbt/double-conversion/utils.h ++++ b/mfbt/double-conversion/utils.h +@@ -68,23 +68,7 @@ + #endif + + +-#if defined(_WIN32) && !defined(__MINGW32__) +- +-typedef signed char int8_t; +-typedef unsigned char uint8_t; +-typedef short int16_t; // NOLINT +-typedef unsigned short uint16_t; // NOLINT +-typedef int int32_t; +-typedef unsigned int uint32_t; +-typedef __int64 int64_t; +-typedef unsigned __int64 uint64_t; +-// intptr_t and friends are defined in crtdefs.h through stdio.h. +- +-#else +- +-#include +- +-#endif ++#include "mozilla/StandardInteger.h" + + // The following macro works on both 32 and 64-bit platforms. + // Usage: instead of writing 0x1234567890123456 From 380e5b6b93de9fbb63ed1279f75efc1cd6104e8b Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Mon, 19 Mar 2012 12:22:32 -0400 Subject: [PATCH 13/14] Bug 614188 - Part 2: import double-conversion sources; r=Waldo --- mfbt/double-conversion/LICENSE | 26 + mfbt/double-conversion/README | 11 + mfbt/double-conversion/bignum-dtoa.cc | 640 ++++++++++++++ mfbt/double-conversion/bignum-dtoa.h | 84 ++ mfbt/double-conversion/bignum.cc | 764 +++++++++++++++++ mfbt/double-conversion/bignum.h | 145 ++++ mfbt/double-conversion/cached-powers.cc | 175 ++++ mfbt/double-conversion/cached-powers.h | 64 ++ mfbt/double-conversion/diy-fp.cc | 57 ++ mfbt/double-conversion/diy-fp.h | 118 +++ mfbt/double-conversion/double-conversion.cc | 888 ++++++++++++++++++++ mfbt/double-conversion/double-conversion.h | 537 ++++++++++++ mfbt/double-conversion/fast-dtoa.cc | 664 +++++++++++++++ mfbt/double-conversion/fast-dtoa.h | 88 ++ mfbt/double-conversion/fixed-dtoa.cc | 402 +++++++++ mfbt/double-conversion/fixed-dtoa.h | 56 ++ mfbt/double-conversion/ieee.h | 398 +++++++++ mfbt/double-conversion/strtod.cc | 554 ++++++++++++ mfbt/double-conversion/strtod.h | 45 + mfbt/double-conversion/utils.h | 293 +++++++ 20 files changed, 6009 insertions(+) create mode 100644 mfbt/double-conversion/LICENSE create mode 100644 mfbt/double-conversion/README create mode 100644 mfbt/double-conversion/bignum-dtoa.cc create mode 100644 mfbt/double-conversion/bignum-dtoa.h create mode 100644 mfbt/double-conversion/bignum.cc create mode 100644 mfbt/double-conversion/bignum.h create mode 100644 mfbt/double-conversion/cached-powers.cc create mode 100644 mfbt/double-conversion/cached-powers.h create mode 100644 mfbt/double-conversion/diy-fp.cc create mode 100644 mfbt/double-conversion/diy-fp.h create mode 100644 mfbt/double-conversion/double-conversion.cc create mode 100644 mfbt/double-conversion/double-conversion.h create mode 100644 mfbt/double-conversion/fast-dtoa.cc create mode 100644 mfbt/double-conversion/fast-dtoa.h create mode 100644 mfbt/double-conversion/fixed-dtoa.cc create mode 100644 mfbt/double-conversion/fixed-dtoa.h create mode 100644 mfbt/double-conversion/ieee.h create mode 100644 mfbt/double-conversion/strtod.cc create mode 100644 mfbt/double-conversion/strtod.h create mode 100644 mfbt/double-conversion/utils.h diff --git a/mfbt/double-conversion/LICENSE b/mfbt/double-conversion/LICENSE new file mode 100644 index 000000000000..933718a9ef9d --- /dev/null +++ b/mfbt/double-conversion/LICENSE @@ -0,0 +1,26 @@ +Copyright 2006-2011, the V8 project authors. All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/mfbt/double-conversion/README b/mfbt/double-conversion/README new file mode 100644 index 000000000000..f186b420f42b --- /dev/null +++ b/mfbt/double-conversion/README @@ -0,0 +1,11 @@ +http://code.google.com/p/double-conversion + +This project (double-conversion) provides binary-decimal and decimal-binary +routines for IEEE doubles. + +The library consists of efficient conversion routines that have been extracted +from the V8 JavaScript engine. The code has been refactored and improved so that +it can be used more easily in other projects. + +There is extensive documentation in src/double-conversion.h. Other examples can +be found in test/cctest/test-conversions.cc. diff --git a/mfbt/double-conversion/bignum-dtoa.cc b/mfbt/double-conversion/bignum-dtoa.cc new file mode 100644 index 000000000000..b6c2e85d17cc --- /dev/null +++ b/mfbt/double-conversion/bignum-dtoa.cc @@ -0,0 +1,640 @@ +// Copyright 2010 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include + +#include "bignum-dtoa.h" + +#include "bignum.h" +#include "ieee.h" + +namespace double_conversion { + +static int NormalizedExponent(uint64_t significand, int exponent) { + ASSERT(significand != 0); + while ((significand & Double::kHiddenBit) == 0) { + significand = significand << 1; + exponent = exponent - 1; + } + return exponent; +} + + +// Forward declarations: +// Returns an estimation of k such that 10^(k-1) <= v < 10^k. +static int EstimatePower(int exponent); +// Computes v / 10^estimated_power exactly, as a ratio of two bignums, numerator +// and denominator. +static void InitialScaledStartValues(uint64_t significand, + int exponent, + bool lower_boundary_is_closer, + int estimated_power, + bool need_boundary_deltas, + Bignum* numerator, + Bignum* denominator, + Bignum* delta_minus, + Bignum* delta_plus); +// Multiplies numerator/denominator so that its values lies in the range 1-10. +// Returns decimal_point s.t. +// v = numerator'/denominator' * 10^(decimal_point-1) +// where numerator' and denominator' are the values of numerator and +// denominator after the call to this function. +static void FixupMultiply10(int estimated_power, bool is_even, + int* decimal_point, + Bignum* numerator, Bignum* denominator, + Bignum* delta_minus, Bignum* delta_plus); +// Generates digits from the left to the right and stops when the generated +// digits yield the shortest decimal representation of v. +static void GenerateShortestDigits(Bignum* numerator, Bignum* denominator, + Bignum* delta_minus, Bignum* delta_plus, + bool is_even, + Vector buffer, int* length); +// Generates 'requested_digits' after the decimal point. +static void BignumToFixed(int requested_digits, int* decimal_point, + Bignum* numerator, Bignum* denominator, + Vector(buffer), int* length); +// Generates 'count' digits of numerator/denominator. +// Once 'count' digits have been produced rounds the result depending on the +// remainder (remainders of exactly .5 round upwards). Might update the +// decimal_point when rounding up (for example for 0.9999). +static void GenerateCountedDigits(int count, int* decimal_point, + Bignum* numerator, Bignum* denominator, + Vector(buffer), int* length); + + +void BignumDtoa(double v, BignumDtoaMode mode, int requested_digits, + Vector buffer, int* length, int* decimal_point) { + ASSERT(v > 0); + ASSERT(!Double(v).IsSpecial()); + uint64_t significand; + int exponent; + bool lower_boundary_is_closer; + if (mode == BIGNUM_DTOA_SHORTEST_SINGLE) { + float f = static_cast(v); + ASSERT(f == v); + significand = Single(f).Significand(); + exponent = Single(f).Exponent(); + lower_boundary_is_closer = Single(f).LowerBoundaryIsCloser(); + } else { + significand = Double(v).Significand(); + exponent = Double(v).Exponent(); + lower_boundary_is_closer = Double(v).LowerBoundaryIsCloser(); + } + bool need_boundary_deltas = + (mode == BIGNUM_DTOA_SHORTEST || mode == BIGNUM_DTOA_SHORTEST_SINGLE); + + bool is_even = (significand & 1) == 0; + int normalized_exponent = NormalizedExponent(significand, exponent); + // estimated_power might be too low by 1. + int estimated_power = EstimatePower(normalized_exponent); + + // Shortcut for Fixed. + // The requested digits correspond to the digits after the point. If the + // number is much too small, then there is no need in trying to get any + // digits. + if (mode == BIGNUM_DTOA_FIXED && -estimated_power - 1 > requested_digits) { + buffer[0] = '\0'; + *length = 0; + // Set decimal-point to -requested_digits. This is what Gay does. + // Note that it should not have any effect anyways since the string is + // empty. + *decimal_point = -requested_digits; + return; + } + + Bignum numerator; + Bignum denominator; + Bignum delta_minus; + Bignum delta_plus; + // Make sure the bignum can grow large enough. The smallest double equals + // 4e-324. In this case the denominator needs fewer than 324*4 binary digits. + // The maximum double is 1.7976931348623157e308 which needs fewer than + // 308*4 binary digits. + ASSERT(Bignum::kMaxSignificantBits >= 324*4); + InitialScaledStartValues(significand, exponent, lower_boundary_is_closer, + estimated_power, need_boundary_deltas, + &numerator, &denominator, + &delta_minus, &delta_plus); + // We now have v = (numerator / denominator) * 10^estimated_power. + FixupMultiply10(estimated_power, is_even, decimal_point, + &numerator, &denominator, + &delta_minus, &delta_plus); + // We now have v = (numerator / denominator) * 10^(decimal_point-1), and + // 1 <= (numerator + delta_plus) / denominator < 10 + switch (mode) { + case BIGNUM_DTOA_SHORTEST: + case BIGNUM_DTOA_SHORTEST_SINGLE: + GenerateShortestDigits(&numerator, &denominator, + &delta_minus, &delta_plus, + is_even, buffer, length); + break; + case BIGNUM_DTOA_FIXED: + BignumToFixed(requested_digits, decimal_point, + &numerator, &denominator, + buffer, length); + break; + case BIGNUM_DTOA_PRECISION: + GenerateCountedDigits(requested_digits, decimal_point, + &numerator, &denominator, + buffer, length); + break; + default: + UNREACHABLE(); + } + buffer[*length] = '\0'; +} + + +// The procedure starts generating digits from the left to the right and stops +// when the generated digits yield the shortest decimal representation of v. A +// decimal representation of v is a number lying closer to v than to any other +// double, so it converts to v when read. +// +// This is true if d, the decimal representation, is between m- and m+, the +// upper and lower boundaries. d must be strictly between them if !is_even. +// m- := (numerator - delta_minus) / denominator +// m+ := (numerator + delta_plus) / denominator +// +// Precondition: 0 <= (numerator+delta_plus) / denominator < 10. +// If 1 <= (numerator+delta_plus) / denominator < 10 then no leading 0 digit +// will be produced. This should be the standard precondition. +static void GenerateShortestDigits(Bignum* numerator, Bignum* denominator, + Bignum* delta_minus, Bignum* delta_plus, + bool is_even, + Vector buffer, int* length) { + // Small optimization: if delta_minus and delta_plus are the same just reuse + // one of the two bignums. + if (Bignum::Equal(*delta_minus, *delta_plus)) { + delta_plus = delta_minus; + } + *length = 0; + while (true) { + uint16_t digit; + digit = numerator->DivideModuloIntBignum(*denominator); + ASSERT(digit <= 9); // digit is a uint16_t and therefore always positive. + // digit = numerator / denominator (integer division). + // numerator = numerator % denominator. + buffer[(*length)++] = digit + '0'; + + // Can we stop already? + // If the remainder of the division is less than the distance to the lower + // boundary we can stop. In this case we simply round down (discarding the + // remainder). + // Similarly we test if we can round up (using the upper boundary). + bool in_delta_room_minus; + bool in_delta_room_plus; + if (is_even) { + in_delta_room_minus = Bignum::LessEqual(*numerator, *delta_minus); + } else { + in_delta_room_minus = Bignum::Less(*numerator, *delta_minus); + } + if (is_even) { + in_delta_room_plus = + Bignum::PlusCompare(*numerator, *delta_plus, *denominator) >= 0; + } else { + in_delta_room_plus = + Bignum::PlusCompare(*numerator, *delta_plus, *denominator) > 0; + } + if (!in_delta_room_minus && !in_delta_room_plus) { + // Prepare for next iteration. + numerator->Times10(); + delta_minus->Times10(); + // We optimized delta_plus to be equal to delta_minus (if they share the + // same value). So don't multiply delta_plus if they point to the same + // object. + if (delta_minus != delta_plus) { + delta_plus->Times10(); + } + } else if (in_delta_room_minus && in_delta_room_plus) { + // Let's see if 2*numerator < denominator. + // If yes, then the next digit would be < 5 and we can round down. + int compare = Bignum::PlusCompare(*numerator, *numerator, *denominator); + if (compare < 0) { + // Remaining digits are less than .5. -> Round down (== do nothing). + } else if (compare > 0) { + // Remaining digits are more than .5 of denominator. -> Round up. + // Note that the last digit could not be a '9' as otherwise the whole + // loop would have stopped earlier. + // We still have an assert here in case the preconditions were not + // satisfied. + ASSERT(buffer[(*length) - 1] != '9'); + buffer[(*length) - 1]++; + } else { + // Halfway case. + // TODO(floitsch): need a way to solve half-way cases. + // For now let's round towards even (since this is what Gay seems to + // do). + + if ((buffer[(*length) - 1] - '0') % 2 == 0) { + // Round down => Do nothing. + } else { + ASSERT(buffer[(*length) - 1] != '9'); + buffer[(*length) - 1]++; + } + } + return; + } else if (in_delta_room_minus) { + // Round down (== do nothing). + return; + } else { // in_delta_room_plus + // Round up. + // Note again that the last digit could not be '9' since this would have + // stopped the loop earlier. + // We still have an ASSERT here, in case the preconditions were not + // satisfied. + ASSERT(buffer[(*length) -1] != '9'); + buffer[(*length) - 1]++; + return; + } + } +} + + +// Let v = numerator / denominator < 10. +// Then we generate 'count' digits of d = x.xxxxx... (without the decimal point) +// from left to right. Once 'count' digits have been produced we decide wether +// to round up or down. Remainders of exactly .5 round upwards. Numbers such +// as 9.999999 propagate a carry all the way, and change the +// exponent (decimal_point), when rounding upwards. +static void GenerateCountedDigits(int count, int* decimal_point, + Bignum* numerator, Bignum* denominator, + Vector(buffer), int* length) { + ASSERT(count >= 0); + for (int i = 0; i < count - 1; ++i) { + uint16_t digit; + digit = numerator->DivideModuloIntBignum(*denominator); + ASSERT(digit <= 9); // digit is a uint16_t and therefore always positive. + // digit = numerator / denominator (integer division). + // numerator = numerator % denominator. + buffer[i] = digit + '0'; + // Prepare for next iteration. + numerator->Times10(); + } + // Generate the last digit. + uint16_t digit; + digit = numerator->DivideModuloIntBignum(*denominator); + if (Bignum::PlusCompare(*numerator, *numerator, *denominator) >= 0) { + digit++; + } + buffer[count - 1] = digit + '0'; + // Correct bad digits (in case we had a sequence of '9's). Propagate the + // carry until we hat a non-'9' or til we reach the first digit. + for (int i = count - 1; i > 0; --i) { + if (buffer[i] != '0' + 10) break; + buffer[i] = '0'; + buffer[i - 1]++; + } + if (buffer[0] == '0' + 10) { + // Propagate a carry past the top place. + buffer[0] = '1'; + (*decimal_point)++; + } + *length = count; +} + + +// Generates 'requested_digits' after the decimal point. It might omit +// trailing '0's. If the input number is too small then no digits at all are +// generated (ex.: 2 fixed digits for 0.00001). +// +// Input verifies: 1 <= (numerator + delta) / denominator < 10. +static void BignumToFixed(int requested_digits, int* decimal_point, + Bignum* numerator, Bignum* denominator, + Vector(buffer), int* length) { + // Note that we have to look at more than just the requested_digits, since + // a number could be rounded up. Example: v=0.5 with requested_digits=0. + // Even though the power of v equals 0 we can't just stop here. + if (-(*decimal_point) > requested_digits) { + // The number is definitively too small. + // Ex: 0.001 with requested_digits == 1. + // Set decimal-point to -requested_digits. This is what Gay does. + // Note that it should not have any effect anyways since the string is + // empty. + *decimal_point = -requested_digits; + *length = 0; + return; + } else if (-(*decimal_point) == requested_digits) { + // We only need to verify if the number rounds down or up. + // Ex: 0.04 and 0.06 with requested_digits == 1. + ASSERT(*decimal_point == -requested_digits); + // Initially the fraction lies in range (1, 10]. Multiply the denominator + // by 10 so that we can compare more easily. + denominator->Times10(); + if (Bignum::PlusCompare(*numerator, *numerator, *denominator) >= 0) { + // If the fraction is >= 0.5 then we have to include the rounded + // digit. + buffer[0] = '1'; + *length = 1; + (*decimal_point)++; + } else { + // Note that we caught most of similar cases earlier. + *length = 0; + } + return; + } else { + // The requested digits correspond to the digits after the point. + // The variable 'needed_digits' includes the digits before the point. + int needed_digits = (*decimal_point) + requested_digits; + GenerateCountedDigits(needed_digits, decimal_point, + numerator, denominator, + buffer, length); + } +} + + +// Returns an estimation of k such that 10^(k-1) <= v < 10^k where +// v = f * 2^exponent and 2^52 <= f < 2^53. +// v is hence a normalized double with the given exponent. The output is an +// approximation for the exponent of the decimal approimation .digits * 10^k. +// +// The result might undershoot by 1 in which case 10^k <= v < 10^k+1. +// Note: this property holds for v's upper boundary m+ too. +// 10^k <= m+ < 10^k+1. +// (see explanation below). +// +// Examples: +// EstimatePower(0) => 16 +// EstimatePower(-52) => 0 +// +// Note: e >= 0 => EstimatedPower(e) > 0. No similar claim can be made for e<0. +static int EstimatePower(int exponent) { + // This function estimates log10 of v where v = f*2^e (with e == exponent). + // Note that 10^floor(log10(v)) <= v, but v <= 10^ceil(log10(v)). + // Note that f is bounded by its container size. Let p = 53 (the double's + // significand size). Then 2^(p-1) <= f < 2^p. + // + // Given that log10(v) == log2(v)/log2(10) and e+(len(f)-1) is quite close + // to log2(v) the function is simplified to (e+(len(f)-1)/log2(10)). + // The computed number undershoots by less than 0.631 (when we compute log3 + // and not log10). + // + // Optimization: since we only need an approximated result this computation + // can be performed on 64 bit integers. On x86/x64 architecture the speedup is + // not really measurable, though. + // + // Since we want to avoid overshooting we decrement by 1e10 so that + // floating-point imprecisions don't affect us. + // + // Explanation for v's boundary m+: the computation takes advantage of + // the fact that 2^(p-1) <= f < 2^p. Boundaries still satisfy this requirement + // (even for denormals where the delta can be much more important). + + const double k1Log10 = 0.30102999566398114; // 1/lg(10) + + // For doubles len(f) == 53 (don't forget the hidden bit). + const int kSignificandSize = Double::kSignificandSize; + double estimate = ceil((exponent + kSignificandSize - 1) * k1Log10 - 1e-10); + return static_cast(estimate); +} + + +// See comments for InitialScaledStartValues. +static void InitialScaledStartValuesPositiveExponent( + uint64_t significand, int exponent, + int estimated_power, bool need_boundary_deltas, + Bignum* numerator, Bignum* denominator, + Bignum* delta_minus, Bignum* delta_plus) { + // A positive exponent implies a positive power. + ASSERT(estimated_power >= 0); + // Since the estimated_power is positive we simply multiply the denominator + // by 10^estimated_power. + + // numerator = v. + numerator->AssignUInt64(significand); + numerator->ShiftLeft(exponent); + // denominator = 10^estimated_power. + denominator->AssignPowerUInt16(10, estimated_power); + + if (need_boundary_deltas) { + // Introduce a common denominator so that the deltas to the boundaries are + // integers. + denominator->ShiftLeft(1); + numerator->ShiftLeft(1); + // Let v = f * 2^e, then m+ - v = 1/2 * 2^e; With the common + // denominator (of 2) delta_plus equals 2^e. + delta_plus->AssignUInt16(1); + delta_plus->ShiftLeft(exponent); + // Same for delta_minus. The adjustments if f == 2^p-1 are done later. + delta_minus->AssignUInt16(1); + delta_minus->ShiftLeft(exponent); + } +} + + +// See comments for InitialScaledStartValues +static void InitialScaledStartValuesNegativeExponentPositivePower( + uint64_t significand, int exponent, + int estimated_power, bool need_boundary_deltas, + Bignum* numerator, Bignum* denominator, + Bignum* delta_minus, Bignum* delta_plus) { + // v = f * 2^e with e < 0, and with estimated_power >= 0. + // This means that e is close to 0 (have a look at how estimated_power is + // computed). + + // numerator = significand + // since v = significand * 2^exponent this is equivalent to + // numerator = v * / 2^-exponent + numerator->AssignUInt64(significand); + // denominator = 10^estimated_power * 2^-exponent (with exponent < 0) + denominator->AssignPowerUInt16(10, estimated_power); + denominator->ShiftLeft(-exponent); + + if (need_boundary_deltas) { + // Introduce a common denominator so that the deltas to the boundaries are + // integers. + denominator->ShiftLeft(1); + numerator->ShiftLeft(1); + // Let v = f * 2^e, then m+ - v = 1/2 * 2^e; With the common + // denominator (of 2) delta_plus equals 2^e. + // Given that the denominator already includes v's exponent the distance + // to the boundaries is simply 1. + delta_plus->AssignUInt16(1); + // Same for delta_minus. The adjustments if f == 2^p-1 are done later. + delta_minus->AssignUInt16(1); + } +} + + +// See comments for InitialScaledStartValues +static void InitialScaledStartValuesNegativeExponentNegativePower( + uint64_t significand, int exponent, + int estimated_power, bool need_boundary_deltas, + Bignum* numerator, Bignum* denominator, + Bignum* delta_minus, Bignum* delta_plus) { + // Instead of multiplying the denominator with 10^estimated_power we + // multiply all values (numerator and deltas) by 10^-estimated_power. + + // Use numerator as temporary container for power_ten. + Bignum* power_ten = numerator; + power_ten->AssignPowerUInt16(10, -estimated_power); + + if (need_boundary_deltas) { + // Since power_ten == numerator we must make a copy of 10^estimated_power + // before we complete the computation of the numerator. + // delta_plus = delta_minus = 10^estimated_power + delta_plus->AssignBignum(*power_ten); + delta_minus->AssignBignum(*power_ten); + } + + // numerator = significand * 2 * 10^-estimated_power + // since v = significand * 2^exponent this is equivalent to + // numerator = v * 10^-estimated_power * 2 * 2^-exponent. + // Remember: numerator has been abused as power_ten. So no need to assign it + // to itself. + ASSERT(numerator == power_ten); + numerator->MultiplyByUInt64(significand); + + // denominator = 2 * 2^-exponent with exponent < 0. + denominator->AssignUInt16(1); + denominator->ShiftLeft(-exponent); + + if (need_boundary_deltas) { + // Introduce a common denominator so that the deltas to the boundaries are + // integers. + numerator->ShiftLeft(1); + denominator->ShiftLeft(1); + // With this shift the boundaries have their correct value, since + // delta_plus = 10^-estimated_power, and + // delta_minus = 10^-estimated_power. + // These assignments have been done earlier. + // The adjustments if f == 2^p-1 (lower boundary is closer) are done later. + } +} + + +// Let v = significand * 2^exponent. +// Computes v / 10^estimated_power exactly, as a ratio of two bignums, numerator +// and denominator. The functions GenerateShortestDigits and +// GenerateCountedDigits will then convert this ratio to its decimal +// representation d, with the required accuracy. +// Then d * 10^estimated_power is the representation of v. +// (Note: the fraction and the estimated_power might get adjusted before +// generating the decimal representation.) +// +// The initial start values consist of: +// - a scaled numerator: s.t. numerator/denominator == v / 10^estimated_power. +// - a scaled (common) denominator. +// optionally (used by GenerateShortestDigits to decide if it has the shortest +// decimal converting back to v): +// - v - m-: the distance to the lower boundary. +// - m+ - v: the distance to the upper boundary. +// +// v, m+, m-, and therefore v - m- and m+ - v all share the same denominator. +// +// Let ep == estimated_power, then the returned values will satisfy: +// v / 10^ep = numerator / denominator. +// v's boundarys m- and m+: +// m- / 10^ep == v / 10^ep - delta_minus / denominator +// m+ / 10^ep == v / 10^ep + delta_plus / denominator +// Or in other words: +// m- == v - delta_minus * 10^ep / denominator; +// m+ == v + delta_plus * 10^ep / denominator; +// +// Since 10^(k-1) <= v < 10^k (with k == estimated_power) +// or 10^k <= v < 10^(k+1) +// we then have 0.1 <= numerator/denominator < 1 +// or 1 <= numerator/denominator < 10 +// +// It is then easy to kickstart the digit-generation routine. +// +// The boundary-deltas are only filled if the mode equals BIGNUM_DTOA_SHORTEST +// or BIGNUM_DTOA_SHORTEST_SINGLE. + +static void InitialScaledStartValues(uint64_t significand, + int exponent, + bool lower_boundary_is_closer, + int estimated_power, + bool need_boundary_deltas, + Bignum* numerator, + Bignum* denominator, + Bignum* delta_minus, + Bignum* delta_plus) { + if (exponent >= 0) { + InitialScaledStartValuesPositiveExponent( + significand, exponent, estimated_power, need_boundary_deltas, + numerator, denominator, delta_minus, delta_plus); + } else if (estimated_power >= 0) { + InitialScaledStartValuesNegativeExponentPositivePower( + significand, exponent, estimated_power, need_boundary_deltas, + numerator, denominator, delta_minus, delta_plus); + } else { + InitialScaledStartValuesNegativeExponentNegativePower( + significand, exponent, estimated_power, need_boundary_deltas, + numerator, denominator, delta_minus, delta_plus); + } + + if (need_boundary_deltas && lower_boundary_is_closer) { + // The lower boundary is closer at half the distance of "normal" numbers. + // Increase the common denominator and adapt all but the delta_minus. + denominator->ShiftLeft(1); // *2 + numerator->ShiftLeft(1); // *2 + delta_plus->ShiftLeft(1); // *2 + } +} + + +// This routine multiplies numerator/denominator so that its values lies in the +// range 1-10. That is after a call to this function we have: +// 1 <= (numerator + delta_plus) /denominator < 10. +// Let numerator the input before modification and numerator' the argument +// after modification, then the output-parameter decimal_point is such that +// numerator / denominator * 10^estimated_power == +// numerator' / denominator' * 10^(decimal_point - 1) +// In some cases estimated_power was too low, and this is already the case. We +// then simply adjust the power so that 10^(k-1) <= v < 10^k (with k == +// estimated_power) but do not touch the numerator or denominator. +// Otherwise the routine multiplies the numerator and the deltas by 10. +static void FixupMultiply10(int estimated_power, bool is_even, + int* decimal_point, + Bignum* numerator, Bignum* denominator, + Bignum* delta_minus, Bignum* delta_plus) { + bool in_range; + if (is_even) { + // For IEEE doubles half-way cases (in decimal system numbers ending with 5) + // are rounded to the closest floating-point number with even significand. + in_range = Bignum::PlusCompare(*numerator, *delta_plus, *denominator) >= 0; + } else { + in_range = Bignum::PlusCompare(*numerator, *delta_plus, *denominator) > 0; + } + if (in_range) { + // Since numerator + delta_plus >= denominator we already have + // 1 <= numerator/denominator < 10. Simply update the estimated_power. + *decimal_point = estimated_power + 1; + } else { + *decimal_point = estimated_power; + numerator->Times10(); + if (Bignum::Equal(*delta_minus, *delta_plus)) { + delta_minus->Times10(); + delta_plus->AssignBignum(*delta_minus); + } else { + delta_minus->Times10(); + delta_plus->Times10(); + } + } +} + +} // namespace double_conversion diff --git a/mfbt/double-conversion/bignum-dtoa.h b/mfbt/double-conversion/bignum-dtoa.h new file mode 100644 index 000000000000..34b961992d67 --- /dev/null +++ b/mfbt/double-conversion/bignum-dtoa.h @@ -0,0 +1,84 @@ +// Copyright 2010 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef DOUBLE_CONVERSION_BIGNUM_DTOA_H_ +#define DOUBLE_CONVERSION_BIGNUM_DTOA_H_ + +#include "utils.h" + +namespace double_conversion { + +enum BignumDtoaMode { + // Return the shortest correct representation. + // For example the output of 0.299999999999999988897 is (the less accurate but + // correct) 0.3. + BIGNUM_DTOA_SHORTEST, + // Same as BIGNUM_DTOA_SHORTEST but for single-precision floats. + BIGNUM_DTOA_SHORTEST_SINGLE, + // Return a fixed number of digits after the decimal point. + // For instance fixed(0.1, 4) becomes 0.1000 + // If the input number is big, the output will be big. + BIGNUM_DTOA_FIXED, + // Return a fixed number of digits, no matter what the exponent is. + BIGNUM_DTOA_PRECISION +}; + +// Converts the given double 'v' to ascii. +// The result should be interpreted as buffer * 10^(point-length). +// The buffer will be null-terminated. +// +// The input v must be > 0 and different from NaN, and Infinity. +// +// The output depends on the given mode: +// - SHORTEST: produce the least amount of digits for which the internal +// identity requirement is still satisfied. If the digits are printed +// (together with the correct exponent) then reading this number will give +// 'v' again. The buffer will choose the representation that is closest to +// 'v'. If there are two at the same distance, than the number is round up. +// In this mode the 'requested_digits' parameter is ignored. +// - FIXED: produces digits necessary to print a given number with +// 'requested_digits' digits after the decimal point. The produced digits +// might be too short in which case the caller has to fill the gaps with '0's. +// Example: toFixed(0.001, 5) is allowed to return buffer="1", point=-2. +// Halfway cases are rounded up. The call toFixed(0.15, 2) thus returns +// buffer="2", point=0. +// Note: the length of the returned buffer has no meaning wrt the significance +// of its digits. That is, just because it contains '0's does not mean that +// any other digit would not satisfy the internal identity requirement. +// - PRECISION: produces 'requested_digits' where the first digit is not '0'. +// Even though the length of produced digits usually equals +// 'requested_digits', the function is allowed to return fewer digits, in +// which case the caller has to fill the missing digits with '0's. +// Halfway cases are again rounded up. +// 'BignumDtoa' expects the given buffer to be big enough to hold all digits +// and a terminating null-character. +void BignumDtoa(double v, BignumDtoaMode mode, int requested_digits, + Vector buffer, int* length, int* point); + +} // namespace double_conversion + +#endif // DOUBLE_CONVERSION_BIGNUM_DTOA_H_ diff --git a/mfbt/double-conversion/bignum.cc b/mfbt/double-conversion/bignum.cc new file mode 100644 index 000000000000..747491a08978 --- /dev/null +++ b/mfbt/double-conversion/bignum.cc @@ -0,0 +1,764 @@ +// Copyright 2010 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "bignum.h" +#include "utils.h" + +namespace double_conversion { + +Bignum::Bignum() + : bigits_(bigits_buffer_, kBigitCapacity), used_digits_(0), exponent_(0) { + for (int i = 0; i < kBigitCapacity; ++i) { + bigits_[i] = 0; + } +} + + +template +static int BitSize(S value) { + return 8 * sizeof(value); +} + +// Guaranteed to lie in one Bigit. +void Bignum::AssignUInt16(uint16_t value) { + ASSERT(kBigitSize >= BitSize(value)); + Zero(); + if (value == 0) return; + + EnsureCapacity(1); + bigits_[0] = value; + used_digits_ = 1; +} + + +void Bignum::AssignUInt64(uint64_t value) { + const int kUInt64Size = 64; + + Zero(); + if (value == 0) return; + + int needed_bigits = kUInt64Size / kBigitSize + 1; + EnsureCapacity(needed_bigits); + for (int i = 0; i < needed_bigits; ++i) { + bigits_[i] = value & kBigitMask; + value = value >> kBigitSize; + } + used_digits_ = needed_bigits; + Clamp(); +} + + +void Bignum::AssignBignum(const Bignum& other) { + exponent_ = other.exponent_; + for (int i = 0; i < other.used_digits_; ++i) { + bigits_[i] = other.bigits_[i]; + } + // Clear the excess digits (if there were any). + for (int i = other.used_digits_; i < used_digits_; ++i) { + bigits_[i] = 0; + } + used_digits_ = other.used_digits_; +} + + +static uint64_t ReadUInt64(Vector buffer, + int from, + int digits_to_read) { + uint64_t result = 0; + for (int i = from; i < from + digits_to_read; ++i) { + int digit = buffer[i] - '0'; + ASSERT(0 <= digit && digit <= 9); + result = result * 10 + digit; + } + return result; +} + + +void Bignum::AssignDecimalString(Vector value) { + // 2^64 = 18446744073709551616 > 10^19 + const int kMaxUint64DecimalDigits = 19; + Zero(); + int length = value.length(); + int pos = 0; + // Let's just say that each digit needs 4 bits. + while (length >= kMaxUint64DecimalDigits) { + uint64_t digits = ReadUInt64(value, pos, kMaxUint64DecimalDigits); + pos += kMaxUint64DecimalDigits; + length -= kMaxUint64DecimalDigits; + MultiplyByPowerOfTen(kMaxUint64DecimalDigits); + AddUInt64(digits); + } + uint64_t digits = ReadUInt64(value, pos, length); + MultiplyByPowerOfTen(length); + AddUInt64(digits); + Clamp(); +} + + +static int HexCharValue(char c) { + if ('0' <= c && c <= '9') return c - '0'; + if ('a' <= c && c <= 'f') return 10 + c - 'a'; + if ('A' <= c && c <= 'F') return 10 + c - 'A'; + UNREACHABLE(); + return 0; // To make compiler happy. +} + + +void Bignum::AssignHexString(Vector value) { + Zero(); + int length = value.length(); + + int needed_bigits = length * 4 / kBigitSize + 1; + EnsureCapacity(needed_bigits); + int string_index = length - 1; + for (int i = 0; i < needed_bigits - 1; ++i) { + // These bigits are guaranteed to be "full". + Chunk current_bigit = 0; + for (int j = 0; j < kBigitSize / 4; j++) { + current_bigit += HexCharValue(value[string_index--]) << (j * 4); + } + bigits_[i] = current_bigit; + } + used_digits_ = needed_bigits - 1; + + Chunk most_significant_bigit = 0; // Could be = 0; + for (int j = 0; j <= string_index; ++j) { + most_significant_bigit <<= 4; + most_significant_bigit += HexCharValue(value[j]); + } + if (most_significant_bigit != 0) { + bigits_[used_digits_] = most_significant_bigit; + used_digits_++; + } + Clamp(); +} + + +void Bignum::AddUInt64(uint64_t operand) { + if (operand == 0) return; + Bignum other; + other.AssignUInt64(operand); + AddBignum(other); +} + + +void Bignum::AddBignum(const Bignum& other) { + ASSERT(IsClamped()); + ASSERT(other.IsClamped()); + + // If this has a greater exponent than other append zero-bigits to this. + // After this call exponent_ <= other.exponent_. + Align(other); + + // There are two possibilities: + // aaaaaaaaaaa 0000 (where the 0s represent a's exponent) + // bbbbb 00000000 + // ---------------- + // ccccccccccc 0000 + // or + // aaaaaaaaaa 0000 + // bbbbbbbbb 0000000 + // ----------------- + // cccccccccccc 0000 + // In both cases we might need a carry bigit. + + EnsureCapacity(1 + Max(BigitLength(), other.BigitLength()) - exponent_); + Chunk carry = 0; + int bigit_pos = other.exponent_ - exponent_; + ASSERT(bigit_pos >= 0); + for (int i = 0; i < other.used_digits_; ++i) { + Chunk sum = bigits_[bigit_pos] + other.bigits_[i] + carry; + bigits_[bigit_pos] = sum & kBigitMask; + carry = sum >> kBigitSize; + bigit_pos++; + } + + while (carry != 0) { + Chunk sum = bigits_[bigit_pos] + carry; + bigits_[bigit_pos] = sum & kBigitMask; + carry = sum >> kBigitSize; + bigit_pos++; + } + used_digits_ = Max(bigit_pos, used_digits_); + ASSERT(IsClamped()); +} + + +void Bignum::SubtractBignum(const Bignum& other) { + ASSERT(IsClamped()); + ASSERT(other.IsClamped()); + // We require this to be bigger than other. + ASSERT(LessEqual(other, *this)); + + Align(other); + + int offset = other.exponent_ - exponent_; + Chunk borrow = 0; + int i; + for (i = 0; i < other.used_digits_; ++i) { + ASSERT((borrow == 0) || (borrow == 1)); + Chunk difference = bigits_[i + offset] - other.bigits_[i] - borrow; + bigits_[i + offset] = difference & kBigitMask; + borrow = difference >> (kChunkSize - 1); + } + while (borrow != 0) { + Chunk difference = bigits_[i + offset] - borrow; + bigits_[i + offset] = difference & kBigitMask; + borrow = difference >> (kChunkSize - 1); + ++i; + } + Clamp(); +} + + +void Bignum::ShiftLeft(int shift_amount) { + if (used_digits_ == 0) return; + exponent_ += shift_amount / kBigitSize; + int local_shift = shift_amount % kBigitSize; + EnsureCapacity(used_digits_ + 1); + BigitsShiftLeft(local_shift); +} + + +void Bignum::MultiplyByUInt32(uint32_t factor) { + if (factor == 1) return; + if (factor == 0) { + Zero(); + return; + } + if (used_digits_ == 0) return; + + // The product of a bigit with the factor is of size kBigitSize + 32. + // Assert that this number + 1 (for the carry) fits into double chunk. + ASSERT(kDoubleChunkSize >= kBigitSize + 32 + 1); + DoubleChunk carry = 0; + for (int i = 0; i < used_digits_; ++i) { + DoubleChunk product = static_cast(factor) * bigits_[i] + carry; + bigits_[i] = static_cast(product & kBigitMask); + carry = (product >> kBigitSize); + } + while (carry != 0) { + EnsureCapacity(used_digits_ + 1); + bigits_[used_digits_] = carry & kBigitMask; + used_digits_++; + carry >>= kBigitSize; + } +} + + +void Bignum::MultiplyByUInt64(uint64_t factor) { + if (factor == 1) return; + if (factor == 0) { + Zero(); + return; + } + ASSERT(kBigitSize < 32); + uint64_t carry = 0; + uint64_t low = factor & 0xFFFFFFFF; + uint64_t high = factor >> 32; + for (int i = 0; i < used_digits_; ++i) { + uint64_t product_low = low * bigits_[i]; + uint64_t product_high = high * bigits_[i]; + uint64_t tmp = (carry & kBigitMask) + product_low; + bigits_[i] = tmp & kBigitMask; + carry = (carry >> kBigitSize) + (tmp >> kBigitSize) + + (product_high << (32 - kBigitSize)); + } + while (carry != 0) { + EnsureCapacity(used_digits_ + 1); + bigits_[used_digits_] = carry & kBigitMask; + used_digits_++; + carry >>= kBigitSize; + } +} + + +void Bignum::MultiplyByPowerOfTen(int exponent) { + const uint64_t kFive27 = UINT64_2PART_C(0x6765c793, fa10079d); + const uint16_t kFive1 = 5; + const uint16_t kFive2 = kFive1 * 5; + const uint16_t kFive3 = kFive2 * 5; + const uint16_t kFive4 = kFive3 * 5; + const uint16_t kFive5 = kFive4 * 5; + const uint16_t kFive6 = kFive5 * 5; + const uint32_t kFive7 = kFive6 * 5; + const uint32_t kFive8 = kFive7 * 5; + const uint32_t kFive9 = kFive8 * 5; + const uint32_t kFive10 = kFive9 * 5; + const uint32_t kFive11 = kFive10 * 5; + const uint32_t kFive12 = kFive11 * 5; + const uint32_t kFive13 = kFive12 * 5; + const uint32_t kFive1_to_12[] = + { kFive1, kFive2, kFive3, kFive4, kFive5, kFive6, + kFive7, kFive8, kFive9, kFive10, kFive11, kFive12 }; + + ASSERT(exponent >= 0); + if (exponent == 0) return; + if (used_digits_ == 0) return; + + // We shift by exponent at the end just before returning. + int remaining_exponent = exponent; + while (remaining_exponent >= 27) { + MultiplyByUInt64(kFive27); + remaining_exponent -= 27; + } + while (remaining_exponent >= 13) { + MultiplyByUInt32(kFive13); + remaining_exponent -= 13; + } + if (remaining_exponent > 0) { + MultiplyByUInt32(kFive1_to_12[remaining_exponent - 1]); + } + ShiftLeft(exponent); +} + + +void Bignum::Square() { + ASSERT(IsClamped()); + int product_length = 2 * used_digits_; + EnsureCapacity(product_length); + + // Comba multiplication: compute each column separately. + // Example: r = a2a1a0 * b2b1b0. + // r = 1 * a0b0 + + // 10 * (a1b0 + a0b1) + + // 100 * (a2b0 + a1b1 + a0b2) + + // 1000 * (a2b1 + a1b2) + + // 10000 * a2b2 + // + // In the worst case we have to accumulate nb-digits products of digit*digit. + // + // Assert that the additional number of bits in a DoubleChunk are enough to + // sum up used_digits of Bigit*Bigit. + if ((1 << (2 * (kChunkSize - kBigitSize))) <= used_digits_) { + UNIMPLEMENTED(); + } + DoubleChunk accumulator = 0; + // First shift the digits so we don't overwrite them. + int copy_offset = used_digits_; + for (int i = 0; i < used_digits_; ++i) { + bigits_[copy_offset + i] = bigits_[i]; + } + // We have two loops to avoid some 'if's in the loop. + for (int i = 0; i < used_digits_; ++i) { + // Process temporary digit i with power i. + // The sum of the two indices must be equal to i. + int bigit_index1 = i; + int bigit_index2 = 0; + // Sum all of the sub-products. + while (bigit_index1 >= 0) { + Chunk chunk1 = bigits_[copy_offset + bigit_index1]; + Chunk chunk2 = bigits_[copy_offset + bigit_index2]; + accumulator += static_cast(chunk1) * chunk2; + bigit_index1--; + bigit_index2++; + } + bigits_[i] = static_cast(accumulator) & kBigitMask; + accumulator >>= kBigitSize; + } + for (int i = used_digits_; i < product_length; ++i) { + int bigit_index1 = used_digits_ - 1; + int bigit_index2 = i - bigit_index1; + // Invariant: sum of both indices is again equal to i. + // Inner loop runs 0 times on last iteration, emptying accumulator. + while (bigit_index2 < used_digits_) { + Chunk chunk1 = bigits_[copy_offset + bigit_index1]; + Chunk chunk2 = bigits_[copy_offset + bigit_index2]; + accumulator += static_cast(chunk1) * chunk2; + bigit_index1--; + bigit_index2++; + } + // The overwritten bigits_[i] will never be read in further loop iterations, + // because bigit_index1 and bigit_index2 are always greater + // than i - used_digits_. + bigits_[i] = static_cast(accumulator) & kBigitMask; + accumulator >>= kBigitSize; + } + // Since the result was guaranteed to lie inside the number the + // accumulator must be 0 now. + ASSERT(accumulator == 0); + + // Don't forget to update the used_digits and the exponent. + used_digits_ = product_length; + exponent_ *= 2; + Clamp(); +} + + +void Bignum::AssignPowerUInt16(uint16_t base, int power_exponent) { + ASSERT(base != 0); + ASSERT(power_exponent >= 0); + if (power_exponent == 0) { + AssignUInt16(1); + return; + } + Zero(); + int shifts = 0; + // We expect base to be in range 2-32, and most often to be 10. + // It does not make much sense to implement different algorithms for counting + // the bits. + while ((base & 1) == 0) { + base >>= 1; + shifts++; + } + int bit_size = 0; + int tmp_base = base; + while (tmp_base != 0) { + tmp_base >>= 1; + bit_size++; + } + int final_size = bit_size * power_exponent; + // 1 extra bigit for the shifting, and one for rounded final_size. + EnsureCapacity(final_size / kBigitSize + 2); + + // Left to Right exponentiation. + int mask = 1; + while (power_exponent >= mask) mask <<= 1; + + // The mask is now pointing to the bit above the most significant 1-bit of + // power_exponent. + // Get rid of first 1-bit; + mask >>= 2; + uint64_t this_value = base; + + bool delayed_multipliciation = false; + const uint64_t max_32bits = 0xFFFFFFFF; + while (mask != 0 && this_value <= max_32bits) { + this_value = this_value * this_value; + // Verify that there is enough space in this_value to perform the + // multiplication. The first bit_size bits must be 0. + if ((power_exponent & mask) != 0) { + uint64_t base_bits_mask = + ~((static_cast(1) << (64 - bit_size)) - 1); + bool high_bits_zero = (this_value & base_bits_mask) == 0; + if (high_bits_zero) { + this_value *= base; + } else { + delayed_multipliciation = true; + } + } + mask >>= 1; + } + AssignUInt64(this_value); + if (delayed_multipliciation) { + MultiplyByUInt32(base); + } + + // Now do the same thing as a bignum. + while (mask != 0) { + Square(); + if ((power_exponent & mask) != 0) { + MultiplyByUInt32(base); + } + mask >>= 1; + } + + // And finally add the saved shifts. + ShiftLeft(shifts * power_exponent); +} + + +// Precondition: this/other < 16bit. +uint16_t Bignum::DivideModuloIntBignum(const Bignum& other) { + ASSERT(IsClamped()); + ASSERT(other.IsClamped()); + ASSERT(other.used_digits_ > 0); + + // Easy case: if we have less digits than the divisor than the result is 0. + // Note: this handles the case where this == 0, too. + if (BigitLength() < other.BigitLength()) { + return 0; + } + + Align(other); + + uint16_t result = 0; + + // Start by removing multiples of 'other' until both numbers have the same + // number of digits. + while (BigitLength() > other.BigitLength()) { + // This naive approach is extremely inefficient if the this divided other + // might be big. This function is implemented for doubleToString where + // the result should be small (less than 10). + ASSERT(other.bigits_[other.used_digits_ - 1] >= ((1 << kBigitSize) / 16)); + // Remove the multiples of the first digit. + // Example this = 23 and other equals 9. -> Remove 2 multiples. + result += bigits_[used_digits_ - 1]; + SubtractTimes(other, bigits_[used_digits_ - 1]); + } + + ASSERT(BigitLength() == other.BigitLength()); + + // Both bignums are at the same length now. + // Since other has more than 0 digits we know that the access to + // bigits_[used_digits_ - 1] is safe. + Chunk this_bigit = bigits_[used_digits_ - 1]; + Chunk other_bigit = other.bigits_[other.used_digits_ - 1]; + + if (other.used_digits_ == 1) { + // Shortcut for easy (and common) case. + int quotient = this_bigit / other_bigit; + bigits_[used_digits_ - 1] = this_bigit - other_bigit * quotient; + result += quotient; + Clamp(); + return result; + } + + int division_estimate = this_bigit / (other_bigit + 1); + result += division_estimate; + SubtractTimes(other, division_estimate); + + if (other_bigit * (division_estimate + 1) > this_bigit) { + // No need to even try to subtract. Even if other's remaining digits were 0 + // another subtraction would be too much. + return result; + } + + while (LessEqual(other, *this)) { + SubtractBignum(other); + result++; + } + return result; +} + + +template +static int SizeInHexChars(S number) { + ASSERT(number > 0); + int result = 0; + while (number != 0) { + number >>= 4; + result++; + } + return result; +} + + +static char HexCharOfValue(int value) { + ASSERT(0 <= value && value <= 16); + if (value < 10) return value + '0'; + return value - 10 + 'A'; +} + + +bool Bignum::ToHexString(char* buffer, int buffer_size) const { + ASSERT(IsClamped()); + // Each bigit must be printable as separate hex-character. + ASSERT(kBigitSize % 4 == 0); + const int kHexCharsPerBigit = kBigitSize / 4; + + if (used_digits_ == 0) { + if (buffer_size < 2) return false; + buffer[0] = '0'; + buffer[1] = '\0'; + return true; + } + // We add 1 for the terminating '\0' character. + int needed_chars = (BigitLength() - 1) * kHexCharsPerBigit + + SizeInHexChars(bigits_[used_digits_ - 1]) + 1; + if (needed_chars > buffer_size) return false; + int string_index = needed_chars - 1; + buffer[string_index--] = '\0'; + for (int i = 0; i < exponent_; ++i) { + for (int j = 0; j < kHexCharsPerBigit; ++j) { + buffer[string_index--] = '0'; + } + } + for (int i = 0; i < used_digits_ - 1; ++i) { + Chunk current_bigit = bigits_[i]; + for (int j = 0; j < kHexCharsPerBigit; ++j) { + buffer[string_index--] = HexCharOfValue(current_bigit & 0xF); + current_bigit >>= 4; + } + } + // And finally the last bigit. + Chunk most_significant_bigit = bigits_[used_digits_ - 1]; + while (most_significant_bigit != 0) { + buffer[string_index--] = HexCharOfValue(most_significant_bigit & 0xF); + most_significant_bigit >>= 4; + } + return true; +} + + +Bignum::Chunk Bignum::BigitAt(int index) const { + if (index >= BigitLength()) return 0; + if (index < exponent_) return 0; + return bigits_[index - exponent_]; +} + + +int Bignum::Compare(const Bignum& a, const Bignum& b) { + ASSERT(a.IsClamped()); + ASSERT(b.IsClamped()); + int bigit_length_a = a.BigitLength(); + int bigit_length_b = b.BigitLength(); + if (bigit_length_a < bigit_length_b) return -1; + if (bigit_length_a > bigit_length_b) return +1; + for (int i = bigit_length_a - 1; i >= Min(a.exponent_, b.exponent_); --i) { + Chunk bigit_a = a.BigitAt(i); + Chunk bigit_b = b.BigitAt(i); + if (bigit_a < bigit_b) return -1; + if (bigit_a > bigit_b) return +1; + // Otherwise they are equal up to this digit. Try the next digit. + } + return 0; +} + + +int Bignum::PlusCompare(const Bignum& a, const Bignum& b, const Bignum& c) { + ASSERT(a.IsClamped()); + ASSERT(b.IsClamped()); + ASSERT(c.IsClamped()); + if (a.BigitLength() < b.BigitLength()) { + return PlusCompare(b, a, c); + } + if (a.BigitLength() + 1 < c.BigitLength()) return -1; + if (a.BigitLength() > c.BigitLength()) return +1; + // The exponent encodes 0-bigits. So if there are more 0-digits in 'a' than + // 'b' has digits, then the bigit-length of 'a'+'b' must be equal to the one + // of 'a'. + if (a.exponent_ >= b.BigitLength() && a.BigitLength() < c.BigitLength()) { + return -1; + } + + Chunk borrow = 0; + // Starting at min_exponent all digits are == 0. So no need to compare them. + int min_exponent = Min(Min(a.exponent_, b.exponent_), c.exponent_); + for (int i = c.BigitLength() - 1; i >= min_exponent; --i) { + Chunk chunk_a = a.BigitAt(i); + Chunk chunk_b = b.BigitAt(i); + Chunk chunk_c = c.BigitAt(i); + Chunk sum = chunk_a + chunk_b; + if (sum > chunk_c + borrow) { + return +1; + } else { + borrow = chunk_c + borrow - sum; + if (borrow > 1) return -1; + borrow <<= kBigitSize; + } + } + if (borrow == 0) return 0; + return -1; +} + + +void Bignum::Clamp() { + while (used_digits_ > 0 && bigits_[used_digits_ - 1] == 0) { + used_digits_--; + } + if (used_digits_ == 0) { + // Zero. + exponent_ = 0; + } +} + + +bool Bignum::IsClamped() const { + return used_digits_ == 0 || bigits_[used_digits_ - 1] != 0; +} + + +void Bignum::Zero() { + for (int i = 0; i < used_digits_; ++i) { + bigits_[i] = 0; + } + used_digits_ = 0; + exponent_ = 0; +} + + +void Bignum::Align(const Bignum& other) { + if (exponent_ > other.exponent_) { + // If "X" represents a "hidden" digit (by the exponent) then we are in the + // following case (a == this, b == other): + // a: aaaaaaXXXX or a: aaaaaXXX + // b: bbbbbbX b: bbbbbbbbXX + // We replace some of the hidden digits (X) of a with 0 digits. + // a: aaaaaa000X or a: aaaaa0XX + int zero_digits = exponent_ - other.exponent_; + EnsureCapacity(used_digits_ + zero_digits); + for (int i = used_digits_ - 1; i >= 0; --i) { + bigits_[i + zero_digits] = bigits_[i]; + } + for (int i = 0; i < zero_digits; ++i) { + bigits_[i] = 0; + } + used_digits_ += zero_digits; + exponent_ -= zero_digits; + ASSERT(used_digits_ >= 0); + ASSERT(exponent_ >= 0); + } +} + + +void Bignum::BigitsShiftLeft(int shift_amount) { + ASSERT(shift_amount < kBigitSize); + ASSERT(shift_amount >= 0); + Chunk carry = 0; + for (int i = 0; i < used_digits_; ++i) { + Chunk new_carry = bigits_[i] >> (kBigitSize - shift_amount); + bigits_[i] = ((bigits_[i] << shift_amount) + carry) & kBigitMask; + carry = new_carry; + } + if (carry != 0) { + bigits_[used_digits_] = carry; + used_digits_++; + } +} + + +void Bignum::SubtractTimes(const Bignum& other, int factor) { + ASSERT(exponent_ <= other.exponent_); + if (factor < 3) { + for (int i = 0; i < factor; ++i) { + SubtractBignum(other); + } + return; + } + Chunk borrow = 0; + int exponent_diff = other.exponent_ - exponent_; + for (int i = 0; i < other.used_digits_; ++i) { + DoubleChunk product = static_cast(factor) * other.bigits_[i]; + DoubleChunk remove = borrow + product; + Chunk difference = bigits_[i + exponent_diff] - (remove & kBigitMask); + bigits_[i + exponent_diff] = difference & kBigitMask; + borrow = static_cast((difference >> (kChunkSize - 1)) + + (remove >> kBigitSize)); + } + for (int i = other.used_digits_ + exponent_diff; i < used_digits_; ++i) { + if (borrow == 0) return; + Chunk difference = bigits_[i] - borrow; + bigits_[i] = difference & kBigitMask; + borrow = difference >> (kChunkSize - 1); + ++i; + } + Clamp(); +} + + +} // namespace double_conversion diff --git a/mfbt/double-conversion/bignum.h b/mfbt/double-conversion/bignum.h new file mode 100644 index 000000000000..5ec3544f573d --- /dev/null +++ b/mfbt/double-conversion/bignum.h @@ -0,0 +1,145 @@ +// Copyright 2010 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef DOUBLE_CONVERSION_BIGNUM_H_ +#define DOUBLE_CONVERSION_BIGNUM_H_ + +#include "utils.h" + +namespace double_conversion { + +class Bignum { + public: + // 3584 = 128 * 28. We can represent 2^3584 > 10^1000 accurately. + // This bignum can encode much bigger numbers, since it contains an + // exponent. + static const int kMaxSignificantBits = 3584; + + Bignum(); + void AssignUInt16(uint16_t value); + void AssignUInt64(uint64_t value); + void AssignBignum(const Bignum& other); + + void AssignDecimalString(Vector value); + void AssignHexString(Vector value); + + void AssignPowerUInt16(uint16_t base, int exponent); + + void AddUInt16(uint16_t operand); + void AddUInt64(uint64_t operand); + void AddBignum(const Bignum& other); + // Precondition: this >= other. + void SubtractBignum(const Bignum& other); + + void Square(); + void ShiftLeft(int shift_amount); + void MultiplyByUInt32(uint32_t factor); + void MultiplyByUInt64(uint64_t factor); + void MultiplyByPowerOfTen(int exponent); + void Times10() { return MultiplyByUInt32(10); } + // Pseudocode: + // int result = this / other; + // this = this % other; + // In the worst case this function is in O(this/other). + uint16_t DivideModuloIntBignum(const Bignum& other); + + bool ToHexString(char* buffer, int buffer_size) const; + + // Returns + // -1 if a < b, + // 0 if a == b, and + // +1 if a > b. + static int Compare(const Bignum& a, const Bignum& b); + static bool Equal(const Bignum& a, const Bignum& b) { + return Compare(a, b) == 0; + } + static bool LessEqual(const Bignum& a, const Bignum& b) { + return Compare(a, b) <= 0; + } + static bool Less(const Bignum& a, const Bignum& b) { + return Compare(a, b) < 0; + } + // Returns Compare(a + b, c); + static int PlusCompare(const Bignum& a, const Bignum& b, const Bignum& c); + // Returns a + b == c + static bool PlusEqual(const Bignum& a, const Bignum& b, const Bignum& c) { + return PlusCompare(a, b, c) == 0; + } + // Returns a + b <= c + static bool PlusLessEqual(const Bignum& a, const Bignum& b, const Bignum& c) { + return PlusCompare(a, b, c) <= 0; + } + // Returns a + b < c + static bool PlusLess(const Bignum& a, const Bignum& b, const Bignum& c) { + return PlusCompare(a, b, c) < 0; + } + private: + typedef uint32_t Chunk; + typedef uint64_t DoubleChunk; + + static const int kChunkSize = sizeof(Chunk) * 8; + static const int kDoubleChunkSize = sizeof(DoubleChunk) * 8; + // With bigit size of 28 we loose some bits, but a double still fits easily + // into two chunks, and more importantly we can use the Comba multiplication. + static const int kBigitSize = 28; + static const Chunk kBigitMask = (1 << kBigitSize) - 1; + // Every instance allocates kBigitLength chunks on the stack. Bignums cannot + // grow. There are no checks if the stack-allocated space is sufficient. + static const int kBigitCapacity = kMaxSignificantBits / kBigitSize; + + void EnsureCapacity(int size) { + if (size > kBigitCapacity) { + UNREACHABLE(); + } + } + void Align(const Bignum& other); + void Clamp(); + bool IsClamped() const; + void Zero(); + // Requires this to have enough capacity (no tests done). + // Updates used_digits_ if necessary. + // shift_amount must be < kBigitSize. + void BigitsShiftLeft(int shift_amount); + // BigitLength includes the "hidden" digits encoded in the exponent. + int BigitLength() const { return used_digits_ + exponent_; } + Chunk BigitAt(int index) const; + void SubtractTimes(const Bignum& other, int factor); + + Chunk bigits_buffer_[kBigitCapacity]; + // A vector backed by bigits_buffer_. This way accesses to the array are + // checked for out-of-bounds errors. + Vector bigits_; + int used_digits_; + // The Bignum's value equals value(bigits_) * 2^(exponent_ * kBigitSize). + int exponent_; + + DISALLOW_COPY_AND_ASSIGN(Bignum); +}; + +} // namespace double_conversion + +#endif // DOUBLE_CONVERSION_BIGNUM_H_ diff --git a/mfbt/double-conversion/cached-powers.cc b/mfbt/double-conversion/cached-powers.cc new file mode 100644 index 000000000000..c676429194e8 --- /dev/null +++ b/mfbt/double-conversion/cached-powers.cc @@ -0,0 +1,175 @@ +// Copyright 2006-2008 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include +#include + +#include "utils.h" + +#include "cached-powers.h" + +namespace double_conversion { + +struct CachedPower { + uint64_t significand; + int16_t binary_exponent; + int16_t decimal_exponent; +}; + +static const CachedPower kCachedPowers[] = { + {UINT64_2PART_C(0xfa8fd5a0, 081c0288), -1220, -348}, + {UINT64_2PART_C(0xbaaee17f, a23ebf76), -1193, -340}, + {UINT64_2PART_C(0x8b16fb20, 3055ac76), -1166, -332}, + {UINT64_2PART_C(0xcf42894a, 5dce35ea), -1140, -324}, + {UINT64_2PART_C(0x9a6bb0aa, 55653b2d), -1113, -316}, + {UINT64_2PART_C(0xe61acf03, 3d1a45df), -1087, -308}, + {UINT64_2PART_C(0xab70fe17, c79ac6ca), -1060, -300}, + {UINT64_2PART_C(0xff77b1fc, bebcdc4f), -1034, -292}, + {UINT64_2PART_C(0xbe5691ef, 416bd60c), -1007, -284}, + {UINT64_2PART_C(0x8dd01fad, 907ffc3c), -980, -276}, + {UINT64_2PART_C(0xd3515c28, 31559a83), -954, -268}, + {UINT64_2PART_C(0x9d71ac8f, ada6c9b5), -927, -260}, + {UINT64_2PART_C(0xea9c2277, 23ee8bcb), -901, -252}, + {UINT64_2PART_C(0xaecc4991, 4078536d), -874, -244}, + {UINT64_2PART_C(0x823c1279, 5db6ce57), -847, -236}, + {UINT64_2PART_C(0xc2109436, 4dfb5637), -821, -228}, + {UINT64_2PART_C(0x9096ea6f, 3848984f), -794, -220}, + {UINT64_2PART_C(0xd77485cb, 25823ac7), -768, -212}, + {UINT64_2PART_C(0xa086cfcd, 97bf97f4), -741, -204}, + {UINT64_2PART_C(0xef340a98, 172aace5), -715, -196}, + {UINT64_2PART_C(0xb23867fb, 2a35b28e), -688, -188}, + {UINT64_2PART_C(0x84c8d4df, d2c63f3b), -661, -180}, + {UINT64_2PART_C(0xc5dd4427, 1ad3cdba), -635, -172}, + {UINT64_2PART_C(0x936b9fce, bb25c996), -608, -164}, + {UINT64_2PART_C(0xdbac6c24, 7d62a584), -582, -156}, + {UINT64_2PART_C(0xa3ab6658, 0d5fdaf6), -555, -148}, + {UINT64_2PART_C(0xf3e2f893, dec3f126), -529, -140}, + {UINT64_2PART_C(0xb5b5ada8, aaff80b8), -502, -132}, + {UINT64_2PART_C(0x87625f05, 6c7c4a8b), -475, -124}, + {UINT64_2PART_C(0xc9bcff60, 34c13053), -449, -116}, + {UINT64_2PART_C(0x964e858c, 91ba2655), -422, -108}, + {UINT64_2PART_C(0xdff97724, 70297ebd), -396, -100}, + {UINT64_2PART_C(0xa6dfbd9f, b8e5b88f), -369, -92}, + {UINT64_2PART_C(0xf8a95fcf, 88747d94), -343, -84}, + {UINT64_2PART_C(0xb9447093, 8fa89bcf), -316, -76}, + {UINT64_2PART_C(0x8a08f0f8, bf0f156b), -289, -68}, + {UINT64_2PART_C(0xcdb02555, 653131b6), -263, -60}, + {UINT64_2PART_C(0x993fe2c6, d07b7fac), -236, -52}, + {UINT64_2PART_C(0xe45c10c4, 2a2b3b06), -210, -44}, + {UINT64_2PART_C(0xaa242499, 697392d3), -183, -36}, + {UINT64_2PART_C(0xfd87b5f2, 8300ca0e), -157, -28}, + {UINT64_2PART_C(0xbce50864, 92111aeb), -130, -20}, + {UINT64_2PART_C(0x8cbccc09, 6f5088cc), -103, -12}, + {UINT64_2PART_C(0xd1b71758, e219652c), -77, -4}, + {UINT64_2PART_C(0x9c400000, 00000000), -50, 4}, + {UINT64_2PART_C(0xe8d4a510, 00000000), -24, 12}, + {UINT64_2PART_C(0xad78ebc5, ac620000), 3, 20}, + {UINT64_2PART_C(0x813f3978, f8940984), 30, 28}, + {UINT64_2PART_C(0xc097ce7b, c90715b3), 56, 36}, + {UINT64_2PART_C(0x8f7e32ce, 7bea5c70), 83, 44}, + {UINT64_2PART_C(0xd5d238a4, abe98068), 109, 52}, + {UINT64_2PART_C(0x9f4f2726, 179a2245), 136, 60}, + {UINT64_2PART_C(0xed63a231, d4c4fb27), 162, 68}, + {UINT64_2PART_C(0xb0de6538, 8cc8ada8), 189, 76}, + {UINT64_2PART_C(0x83c7088e, 1aab65db), 216, 84}, + {UINT64_2PART_C(0xc45d1df9, 42711d9a), 242, 92}, + {UINT64_2PART_C(0x924d692c, a61be758), 269, 100}, + {UINT64_2PART_C(0xda01ee64, 1a708dea), 295, 108}, + {UINT64_2PART_C(0xa26da399, 9aef774a), 322, 116}, + {UINT64_2PART_C(0xf209787b, b47d6b85), 348, 124}, + {UINT64_2PART_C(0xb454e4a1, 79dd1877), 375, 132}, + {UINT64_2PART_C(0x865b8692, 5b9bc5c2), 402, 140}, + {UINT64_2PART_C(0xc83553c5, c8965d3d), 428, 148}, + {UINT64_2PART_C(0x952ab45c, fa97a0b3), 455, 156}, + {UINT64_2PART_C(0xde469fbd, 99a05fe3), 481, 164}, + {UINT64_2PART_C(0xa59bc234, db398c25), 508, 172}, + {UINT64_2PART_C(0xf6c69a72, a3989f5c), 534, 180}, + {UINT64_2PART_C(0xb7dcbf53, 54e9bece), 561, 188}, + {UINT64_2PART_C(0x88fcf317, f22241e2), 588, 196}, + {UINT64_2PART_C(0xcc20ce9b, d35c78a5), 614, 204}, + {UINT64_2PART_C(0x98165af3, 7b2153df), 641, 212}, + {UINT64_2PART_C(0xe2a0b5dc, 971f303a), 667, 220}, + {UINT64_2PART_C(0xa8d9d153, 5ce3b396), 694, 228}, + {UINT64_2PART_C(0xfb9b7cd9, a4a7443c), 720, 236}, + {UINT64_2PART_C(0xbb764c4c, a7a44410), 747, 244}, + {UINT64_2PART_C(0x8bab8eef, b6409c1a), 774, 252}, + {UINT64_2PART_C(0xd01fef10, a657842c), 800, 260}, + {UINT64_2PART_C(0x9b10a4e5, e9913129), 827, 268}, + {UINT64_2PART_C(0xe7109bfb, a19c0c9d), 853, 276}, + {UINT64_2PART_C(0xac2820d9, 623bf429), 880, 284}, + {UINT64_2PART_C(0x80444b5e, 7aa7cf85), 907, 292}, + {UINT64_2PART_C(0xbf21e440, 03acdd2d), 933, 300}, + {UINT64_2PART_C(0x8e679c2f, 5e44ff8f), 960, 308}, + {UINT64_2PART_C(0xd433179d, 9c8cb841), 986, 316}, + {UINT64_2PART_C(0x9e19db92, b4e31ba9), 1013, 324}, + {UINT64_2PART_C(0xeb96bf6e, badf77d9), 1039, 332}, + {UINT64_2PART_C(0xaf87023b, 9bf0ee6b), 1066, 340}, +}; + +static const int kCachedPowersLength = ARRAY_SIZE(kCachedPowers); +static const int kCachedPowersOffset = 348; // -1 * the first decimal_exponent. +static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10) +// Difference between the decimal exponents in the table above. +const int PowersOfTenCache::kDecimalExponentDistance = 8; +const int PowersOfTenCache::kMinDecimalExponent = -348; +const int PowersOfTenCache::kMaxDecimalExponent = 340; + +void PowersOfTenCache::GetCachedPowerForBinaryExponentRange( + int min_exponent, + int max_exponent, + DiyFp* power, + int* decimal_exponent) { + int kQ = DiyFp::kSignificandSize; + double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10); + int foo = kCachedPowersOffset; + int index = + (foo + static_cast(k) - 1) / kDecimalExponentDistance + 1; + ASSERT(0 <= index && index < kCachedPowersLength); + CachedPower cached_power = kCachedPowers[index]; + ASSERT(min_exponent <= cached_power.binary_exponent); + ASSERT(cached_power.binary_exponent <= max_exponent); + *decimal_exponent = cached_power.decimal_exponent; + *power = DiyFp(cached_power.significand, cached_power.binary_exponent); +} + + +void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_exponent, + DiyFp* power, + int* found_exponent) { + ASSERT(kMinDecimalExponent <= requested_exponent); + ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistance); + int index = + (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance; + CachedPower cached_power = kCachedPowers[index]; + *power = DiyFp(cached_power.significand, cached_power.binary_exponent); + *found_exponent = cached_power.decimal_exponent; + ASSERT(*found_exponent <= requested_exponent); + ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance); +} + +} // namespace double_conversion diff --git a/mfbt/double-conversion/cached-powers.h b/mfbt/double-conversion/cached-powers.h new file mode 100644 index 000000000000..61a50614cf10 --- /dev/null +++ b/mfbt/double-conversion/cached-powers.h @@ -0,0 +1,64 @@ +// Copyright 2010 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef DOUBLE_CONVERSION_CACHED_POWERS_H_ +#define DOUBLE_CONVERSION_CACHED_POWERS_H_ + +#include "diy-fp.h" + +namespace double_conversion { + +class PowersOfTenCache { + public: + + // Not all powers of ten are cached. The decimal exponent of two neighboring + // cached numbers will differ by kDecimalExponentDistance. + static const int kDecimalExponentDistance; + + static const int kMinDecimalExponent; + static const int kMaxDecimalExponent; + + // Returns a cached power-of-ten with a binary exponent in the range + // [min_exponent; max_exponent] (boundaries included). + static void GetCachedPowerForBinaryExponentRange(int min_exponent, + int max_exponent, + DiyFp* power, + int* decimal_exponent); + + // Returns a cached power of ten x ~= 10^k such that + // k <= decimal_exponent < k + kCachedPowersDecimalDistance. + // The given decimal_exponent must satisfy + // kMinDecimalExponent <= requested_exponent, and + // requested_exponent < kMaxDecimalExponent + kDecimalExponentDistance. + static void GetCachedPowerForDecimalExponent(int requested_exponent, + DiyFp* power, + int* found_exponent); +}; + +} // namespace double_conversion + +#endif // DOUBLE_CONVERSION_CACHED_POWERS_H_ diff --git a/mfbt/double-conversion/diy-fp.cc b/mfbt/double-conversion/diy-fp.cc new file mode 100644 index 000000000000..ddd1891b168a --- /dev/null +++ b/mfbt/double-conversion/diy-fp.cc @@ -0,0 +1,57 @@ +// Copyright 2010 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +#include "diy-fp.h" +#include "utils.h" + +namespace double_conversion { + +void DiyFp::Multiply(const DiyFp& other) { + // Simply "emulates" a 128 bit multiplication. + // However: the resulting number only contains 64 bits. The least + // significant 64 bits are only used for rounding the most significant 64 + // bits. + const uint64_t kM32 = 0xFFFFFFFFU; + uint64_t a = f_ >> 32; + uint64_t b = f_ & kM32; + uint64_t c = other.f_ >> 32; + uint64_t d = other.f_ & kM32; + uint64_t ac = a * c; + uint64_t bc = b * c; + uint64_t ad = a * d; + uint64_t bd = b * d; + uint64_t tmp = (bd >> 32) + (ad & kM32) + (bc & kM32); + // By adding 1U << 31 to tmp we round the final result. + // Halfway cases will be round up. + tmp += 1U << 31; + uint64_t result_f = ac + (ad >> 32) + (bc >> 32) + (tmp >> 32); + e_ += other.e_ + 64; + f_ = result_f; +} + +} // namespace double_conversion diff --git a/mfbt/double-conversion/diy-fp.h b/mfbt/double-conversion/diy-fp.h new file mode 100644 index 000000000000..9dcf8fbdba99 --- /dev/null +++ b/mfbt/double-conversion/diy-fp.h @@ -0,0 +1,118 @@ +// Copyright 2010 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef DOUBLE_CONVERSION_DIY_FP_H_ +#define DOUBLE_CONVERSION_DIY_FP_H_ + +#include "utils.h" + +namespace double_conversion { + +// This "Do It Yourself Floating Point" class implements a floating-point number +// with a uint64 significand and an int exponent. Normalized DiyFp numbers will +// have the most significant bit of the significand set. +// Multiplication and Subtraction do not normalize their results. +// DiyFp are not designed to contain special doubles (NaN and Infinity). +class DiyFp { + public: + static const int kSignificandSize = 64; + + DiyFp() : f_(0), e_(0) {} + DiyFp(uint64_t f, int e) : f_(f), e_(e) {} + + // this = this - other. + // The exponents of both numbers must be the same and the significand of this + // must be bigger than the significand of other. + // The result will not be normalized. + void Subtract(const DiyFp& other) { + ASSERT(e_ == other.e_); + ASSERT(f_ >= other.f_); + f_ -= other.f_; + } + + // Returns a - b. + // The exponents of both numbers must be the same and this must be bigger + // than other. The result will not be normalized. + static DiyFp Minus(const DiyFp& a, const DiyFp& b) { + DiyFp result = a; + result.Subtract(b); + return result; + } + + + // this = this * other. + void Multiply(const DiyFp& other); + + // returns a * b; + static DiyFp Times(const DiyFp& a, const DiyFp& b) { + DiyFp result = a; + result.Multiply(b); + return result; + } + + void Normalize() { + ASSERT(f_ != 0); + uint64_t f = f_; + int e = e_; + + // This method is mainly called for normalizing boundaries. In general + // boundaries need to be shifted by 10 bits. We thus optimize for this case. + const uint64_t k10MSBits = UINT64_2PART_C(0xFFC00000, 00000000); + while ((f & k10MSBits) == 0) { + f <<= 10; + e -= 10; + } + while ((f & kUint64MSB) == 0) { + f <<= 1; + e--; + } + f_ = f; + e_ = e; + } + + static DiyFp Normalize(const DiyFp& a) { + DiyFp result = a; + result.Normalize(); + return result; + } + + uint64_t f() const { return f_; } + int e() const { return e_; } + + void set_f(uint64_t new_value) { f_ = new_value; } + void set_e(int new_value) { e_ = new_value; } + + private: + static const uint64_t kUint64MSB = UINT64_2PART_C(0x80000000, 00000000); + + uint64_t f_; + int e_; +}; + +} // namespace double_conversion + +#endif // DOUBLE_CONVERSION_DIY_FP_H_ diff --git a/mfbt/double-conversion/double-conversion.cc b/mfbt/double-conversion/double-conversion.cc new file mode 100644 index 000000000000..f0d332bd822e --- /dev/null +++ b/mfbt/double-conversion/double-conversion.cc @@ -0,0 +1,888 @@ +// Copyright 2010 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include + +#include "double-conversion.h" + +#include "bignum-dtoa.h" +#include "fast-dtoa.h" +#include "fixed-dtoa.h" +#include "ieee.h" +#include "strtod.h" +#include "utils.h" + +namespace double_conversion { + +const DoubleToStringConverter& DoubleToStringConverter::EcmaScriptConverter() { + int flags = UNIQUE_ZERO | EMIT_POSITIVE_EXPONENT_SIGN; + static DoubleToStringConverter converter(flags, + "Infinity", + "NaN", + 'e', + -6, 21, + 6, 0); + return converter; +} + + +bool DoubleToStringConverter::HandleSpecialValues( + double value, + StringBuilder* result_builder) const { + Double double_inspect(value); + if (double_inspect.IsInfinite()) { + if (infinity_symbol_ == NULL) return false; + if (value < 0) { + result_builder->AddCharacter('-'); + } + result_builder->AddString(infinity_symbol_); + return true; + } + if (double_inspect.IsNan()) { + if (nan_symbol_ == NULL) return false; + result_builder->AddString(nan_symbol_); + return true; + } + return false; +} + + +void DoubleToStringConverter::CreateExponentialRepresentation( + const char* decimal_digits, + int length, + int exponent, + StringBuilder* result_builder) const { + ASSERT(length != 0); + result_builder->AddCharacter(decimal_digits[0]); + if (length != 1) { + result_builder->AddCharacter('.'); + result_builder->AddSubstring(&decimal_digits[1], length-1); + } + result_builder->AddCharacter(exponent_character_); + if (exponent < 0) { + result_builder->AddCharacter('-'); + exponent = -exponent; + } else { + if ((flags_ & EMIT_POSITIVE_EXPONENT_SIGN) != 0) { + result_builder->AddCharacter('+'); + } + } + if (exponent == 0) { + result_builder->AddCharacter('0'); + return; + } + ASSERT(exponent < 1e4); + const int kMaxExponentLength = 5; + char buffer[kMaxExponentLength]; + int first_char_pos = kMaxExponentLength; + while (exponent > 0) { + buffer[--first_char_pos] = '0' + (exponent % 10); + exponent /= 10; + } + result_builder->AddSubstring(&buffer[first_char_pos], + kMaxExponentLength - first_char_pos); +} + + +void DoubleToStringConverter::CreateDecimalRepresentation( + const char* decimal_digits, + int length, + int decimal_point, + int digits_after_point, + StringBuilder* result_builder) const { + // Create a representation that is padded with zeros if needed. + if (decimal_point <= 0) { + // "0.00000decimal_rep". + result_builder->AddCharacter('0'); + if (digits_after_point > 0) { + result_builder->AddCharacter('.'); + result_builder->AddPadding('0', -decimal_point); + ASSERT(length <= digits_after_point - (-decimal_point)); + result_builder->AddSubstring(decimal_digits, length); + int remaining_digits = digits_after_point - (-decimal_point) - length; + result_builder->AddPadding('0', remaining_digits); + } + } else if (decimal_point >= length) { + // "decimal_rep0000.00000" or "decimal_rep.0000" + result_builder->AddSubstring(decimal_digits, length); + result_builder->AddPadding('0', decimal_point - length); + if (digits_after_point > 0) { + result_builder->AddCharacter('.'); + result_builder->AddPadding('0', digits_after_point); + } + } else { + // "decima.l_rep000" + ASSERT(digits_after_point > 0); + result_builder->AddSubstring(decimal_digits, decimal_point); + result_builder->AddCharacter('.'); + ASSERT(length - decimal_point <= digits_after_point); + result_builder->AddSubstring(&decimal_digits[decimal_point], + length - decimal_point); + int remaining_digits = digits_after_point - (length - decimal_point); + result_builder->AddPadding('0', remaining_digits); + } + if (digits_after_point == 0) { + if ((flags_ & EMIT_TRAILING_DECIMAL_POINT) != 0) { + result_builder->AddCharacter('.'); + } + if ((flags_ & EMIT_TRAILING_ZERO_AFTER_POINT) != 0) { + result_builder->AddCharacter('0'); + } + } +} + + +bool DoubleToStringConverter::ToShortestIeeeNumber( + double value, + StringBuilder* result_builder, + DoubleToStringConverter::DtoaMode mode) const { + assert(mode == SHORTEST || mode == SHORTEST_SINGLE); + if (Double(value).IsSpecial()) { + return HandleSpecialValues(value, result_builder); + } + + int decimal_point; + bool sign; + const int kDecimalRepCapacity = kBase10MaximalLength + 1; + char decimal_rep[kDecimalRepCapacity]; + int decimal_rep_length; + + DoubleToAscii(value, mode, 0, decimal_rep, kDecimalRepCapacity, + &sign, &decimal_rep_length, &decimal_point); + + bool unique_zero = (flags_ & UNIQUE_ZERO) != 0; + if (sign && (value != 0.0 || !unique_zero)) { + result_builder->AddCharacter('-'); + } + + int exponent = decimal_point - 1; + if ((decimal_in_shortest_low_ <= exponent) && + (exponent < decimal_in_shortest_high_)) { + CreateDecimalRepresentation(decimal_rep, decimal_rep_length, + decimal_point, + Max(0, decimal_rep_length - decimal_point), + result_builder); + } else { + CreateExponentialRepresentation(decimal_rep, decimal_rep_length, exponent, + result_builder); + } + return true; +} + + +bool DoubleToStringConverter::ToFixed(double value, + int requested_digits, + StringBuilder* result_builder) const { + ASSERT(kMaxFixedDigitsBeforePoint == 60); + const double kFirstNonFixed = 1e60; + + if (Double(value).IsSpecial()) { + return HandleSpecialValues(value, result_builder); + } + + if (requested_digits > kMaxFixedDigitsAfterPoint) return false; + if (value >= kFirstNonFixed || value <= -kFirstNonFixed) return false; + + // Find a sufficiently precise decimal representation of n. + int decimal_point; + bool sign; + // Add space for the '\0' byte. + const int kDecimalRepCapacity = + kMaxFixedDigitsBeforePoint + kMaxFixedDigitsAfterPoint + 1; + char decimal_rep[kDecimalRepCapacity]; + int decimal_rep_length; + DoubleToAscii(value, FIXED, requested_digits, + decimal_rep, kDecimalRepCapacity, + &sign, &decimal_rep_length, &decimal_point); + + bool unique_zero = ((flags_ & UNIQUE_ZERO) != 0); + if (sign && (value != 0.0 || !unique_zero)) { + result_builder->AddCharacter('-'); + } + + CreateDecimalRepresentation(decimal_rep, decimal_rep_length, decimal_point, + requested_digits, result_builder); + return true; +} + + +bool DoubleToStringConverter::ToExponential( + double value, + int requested_digits, + StringBuilder* result_builder) const { + if (Double(value).IsSpecial()) { + return HandleSpecialValues(value, result_builder); + } + + if (requested_digits < -1) return false; + if (requested_digits > kMaxExponentialDigits) return false; + + int decimal_point; + bool sign; + // Add space for digit before the decimal point and the '\0' character. + const int kDecimalRepCapacity = kMaxExponentialDigits + 2; + ASSERT(kDecimalRepCapacity > kBase10MaximalLength); + char decimal_rep[kDecimalRepCapacity]; + int decimal_rep_length; + + if (requested_digits == -1) { + DoubleToAscii(value, SHORTEST, 0, + decimal_rep, kDecimalRepCapacity, + &sign, &decimal_rep_length, &decimal_point); + } else { + DoubleToAscii(value, PRECISION, requested_digits + 1, + decimal_rep, kDecimalRepCapacity, + &sign, &decimal_rep_length, &decimal_point); + ASSERT(decimal_rep_length <= requested_digits + 1); + + for (int i = decimal_rep_length; i < requested_digits + 1; ++i) { + decimal_rep[i] = '0'; + } + decimal_rep_length = requested_digits + 1; + } + + bool unique_zero = ((flags_ & UNIQUE_ZERO) != 0); + if (sign && (value != 0.0 || !unique_zero)) { + result_builder->AddCharacter('-'); + } + + int exponent = decimal_point - 1; + CreateExponentialRepresentation(decimal_rep, + decimal_rep_length, + exponent, + result_builder); + return true; +} + + +bool DoubleToStringConverter::ToPrecision(double value, + int precision, + StringBuilder* result_builder) const { + if (Double(value).IsSpecial()) { + return HandleSpecialValues(value, result_builder); + } + + if (precision < kMinPrecisionDigits || precision > kMaxPrecisionDigits) { + return false; + } + + // Find a sufficiently precise decimal representation of n. + int decimal_point; + bool sign; + // Add one for the terminating null character. + const int kDecimalRepCapacity = kMaxPrecisionDigits + 1; + char decimal_rep[kDecimalRepCapacity]; + int decimal_rep_length; + + DoubleToAscii(value, PRECISION, precision, + decimal_rep, kDecimalRepCapacity, + &sign, &decimal_rep_length, &decimal_point); + ASSERT(decimal_rep_length <= precision); + + bool unique_zero = ((flags_ & UNIQUE_ZERO) != 0); + if (sign && (value != 0.0 || !unique_zero)) { + result_builder->AddCharacter('-'); + } + + // The exponent if we print the number as x.xxeyyy. That is with the + // decimal point after the first digit. + int exponent = decimal_point - 1; + + int extra_zero = ((flags_ & EMIT_TRAILING_ZERO_AFTER_POINT) != 0) ? 1 : 0; + if ((-decimal_point + 1 > max_leading_padding_zeroes_in_precision_mode_) || + (decimal_point - precision + extra_zero > + max_trailing_padding_zeroes_in_precision_mode_)) { + // Fill buffer to contain 'precision' digits. + // Usually the buffer is already at the correct length, but 'DoubleToAscii' + // is allowed to return less characters. + for (int i = decimal_rep_length; i < precision; ++i) { + decimal_rep[i] = '0'; + } + + CreateExponentialRepresentation(decimal_rep, + precision, + exponent, + result_builder); + } else { + CreateDecimalRepresentation(decimal_rep, decimal_rep_length, decimal_point, + Max(0, precision - decimal_point), + result_builder); + } + return true; +} + + +static BignumDtoaMode DtoaToBignumDtoaMode( + DoubleToStringConverter::DtoaMode dtoa_mode) { + switch (dtoa_mode) { + case DoubleToStringConverter::SHORTEST: return BIGNUM_DTOA_SHORTEST; + case DoubleToStringConverter::SHORTEST_SINGLE: + return BIGNUM_DTOA_SHORTEST_SINGLE; + case DoubleToStringConverter::FIXED: return BIGNUM_DTOA_FIXED; + case DoubleToStringConverter::PRECISION: return BIGNUM_DTOA_PRECISION; + default: + UNREACHABLE(); + return BIGNUM_DTOA_SHORTEST; // To silence compiler. + } +} + + +void DoubleToStringConverter::DoubleToAscii(double v, + DtoaMode mode, + int requested_digits, + char* buffer, + int buffer_length, + bool* sign, + int* length, + int* point) { + Vector vector(buffer, buffer_length); + ASSERT(!Double(v).IsSpecial()); + ASSERT(mode == SHORTEST || mode == SHORTEST_SINGLE || requested_digits >= 0); + + if (Double(v).Sign() < 0) { + *sign = true; + v = -v; + } else { + *sign = false; + } + + if (mode == PRECISION && requested_digits == 0) { + vector[0] = '\0'; + *length = 0; + return; + } + + if (v == 0) { + vector[0] = '0'; + vector[1] = '\0'; + *length = 1; + *point = 1; + return; + } + + bool fast_worked; + switch (mode) { + case SHORTEST: + fast_worked = FastDtoa(v, FAST_DTOA_SHORTEST, 0, vector, length, point); + break; + case SHORTEST_SINGLE: + fast_worked = FastDtoa(v, FAST_DTOA_SHORTEST_SINGLE, 0, + vector, length, point); + break; + case FIXED: + fast_worked = FastFixedDtoa(v, requested_digits, vector, length, point); + break; + case PRECISION: + fast_worked = FastDtoa(v, FAST_DTOA_PRECISION, requested_digits, + vector, length, point); + break; + default: + UNREACHABLE(); + fast_worked = false; + } + if (fast_worked) return; + + // If the fast dtoa didn't succeed use the slower bignum version. + BignumDtoaMode bignum_mode = DtoaToBignumDtoaMode(mode); + BignumDtoa(v, bignum_mode, requested_digits, vector, length, point); + vector[*length] = '\0'; +} + + +// Consumes the given substring from the iterator. +// Returns false, if the substring does not match. +static bool ConsumeSubString(const char** current, + const char* end, + const char* substring) { + ASSERT(**current == *substring); + for (substring++; *substring != '\0'; substring++) { + ++*current; + if (*current == end || **current != *substring) return false; + } + ++*current; + return true; +} + + +// Maximum number of significant digits in decimal representation. +// The longest possible double in decimal representation is +// (2^53 - 1) * 2 ^ -1074 that is (2 ^ 53 - 1) * 5 ^ 1074 / 10 ^ 1074 +// (768 digits). If we parse a number whose first digits are equal to a +// mean of 2 adjacent doubles (that could have up to 769 digits) the result +// must be rounded to the bigger one unless the tail consists of zeros, so +// we don't need to preserve all the digits. +const int kMaxSignificantDigits = 772; + + +// Returns true if a nonspace found and false if the end has reached. +static inline bool AdvanceToNonspace(const char** current, const char* end) { + while (*current != end) { + if (**current != ' ') return true; + ++*current; + } + return false; +} + + +static bool isDigit(int x, int radix) { + return (x >= '0' && x <= '9' && x < '0' + radix) + || (radix > 10 && x >= 'a' && x < 'a' + radix - 10) + || (radix > 10 && x >= 'A' && x < 'A' + radix - 10); +} + + +static double SignedZero(bool sign) { + return sign ? -0.0 : 0.0; +} + + +// Parsing integers with radix 2, 4, 8, 16, 32. Assumes current != end. +template +static double RadixStringToIeee(const char* current, + const char* end, + bool sign, + bool allow_trailing_junk, + double junk_string_value, + bool read_as_double, + const char** trailing_pointer) { + ASSERT(current != end); + + const int kDoubleSize = Double::kSignificandSize; + const int kSingleSize = Single::kSignificandSize; + const int kSignificandSize = read_as_double? kDoubleSize: kSingleSize; + + // Skip leading 0s. + while (*current == '0') { + ++current; + if (current == end) { + *trailing_pointer = end; + return SignedZero(sign); + } + } + + int64_t number = 0; + int exponent = 0; + const int radix = (1 << radix_log_2); + + do { + int digit; + if (*current >= '0' && *current <= '9' && *current < '0' + radix) { + digit = static_cast(*current) - '0'; + } else if (radix > 10 && *current >= 'a' && *current < 'a' + radix - 10) { + digit = static_cast(*current) - 'a' + 10; + } else if (radix > 10 && *current >= 'A' && *current < 'A' + radix - 10) { + digit = static_cast(*current) - 'A' + 10; + } else { + if (allow_trailing_junk || !AdvanceToNonspace(¤t, end)) { + break; + } else { + return junk_string_value; + } + } + + number = number * radix + digit; + int overflow = static_cast(number >> kSignificandSize); + if (overflow != 0) { + // Overflow occurred. Need to determine which direction to round the + // result. + int overflow_bits_count = 1; + while (overflow > 1) { + overflow_bits_count++; + overflow >>= 1; + } + + int dropped_bits_mask = ((1 << overflow_bits_count) - 1); + int dropped_bits = static_cast(number) & dropped_bits_mask; + number >>= overflow_bits_count; + exponent = overflow_bits_count; + + bool zero_tail = true; + while (true) { + ++current; + if (current == end || !isDigit(*current, radix)) break; + zero_tail = zero_tail && *current == '0'; + exponent += radix_log_2; + } + + if (!allow_trailing_junk && AdvanceToNonspace(¤t, end)) { + return junk_string_value; + } + + int middle_value = (1 << (overflow_bits_count - 1)); + if (dropped_bits > middle_value) { + number++; // Rounding up. + } else if (dropped_bits == middle_value) { + // Rounding to even to consistency with decimals: half-way case rounds + // up if significant part is odd and down otherwise. + if ((number & 1) != 0 || !zero_tail) { + number++; // Rounding up. + } + } + + // Rounding up may cause overflow. + if ((number & ((int64_t)1 << kSignificandSize)) != 0) { + exponent++; + number >>= 1; + } + break; + } + ++current; + } while (current != end); + + ASSERT(number < ((int64_t)1 << kSignificandSize)); + ASSERT(static_cast(static_cast(number)) == number); + + *trailing_pointer = current; + + if (exponent == 0) { + if (sign) { + if (number == 0) return -0.0; + number = -number; + } + return static_cast(number); + } + + ASSERT(number != 0); + return Double(DiyFp(number, exponent)).value(); +} + + +double StringToDoubleConverter::StringToIeee( + const char* input, + int length, + int* processed_characters_count, + bool read_as_double) { + const char* current = input; + const char* end = input + length; + + *processed_characters_count = 0; + + const bool allow_trailing_junk = (flags_ & ALLOW_TRAILING_JUNK) != 0; + const bool allow_leading_spaces = (flags_ & ALLOW_LEADING_SPACES) != 0; + const bool allow_trailing_spaces = (flags_ & ALLOW_TRAILING_SPACES) != 0; + const bool allow_spaces_after_sign = (flags_ & ALLOW_SPACES_AFTER_SIGN) != 0; + + // To make sure that iterator dereferencing is valid the following + // convention is used: + // 1. Each '++current' statement is followed by check for equality to 'end'. + // 2. If AdvanceToNonspace returned false then current == end. + // 3. If 'current' becomes equal to 'end' the function returns or goes to + // 'parsing_done'. + // 4. 'current' is not dereferenced after the 'parsing_done' label. + // 5. Code before 'parsing_done' may rely on 'current != end'. + if (current == end) return empty_string_value_; + + if (allow_leading_spaces || allow_trailing_spaces) { + if (!AdvanceToNonspace(¤t, end)) { + *processed_characters_count = current - input; + return empty_string_value_; + } + if (!allow_leading_spaces && (input != current)) { + // No leading spaces allowed, but AdvanceToNonspace moved forward. + return junk_string_value_; + } + } + + // The longest form of simplified number is: "-.1eXXX\0". + const int kBufferSize = kMaxSignificantDigits + 10; + char buffer[kBufferSize]; // NOLINT: size is known at compile time. + int buffer_pos = 0; + + // Exponent will be adjusted if insignificant digits of the integer part + // or insignificant leading zeros of the fractional part are dropped. + int exponent = 0; + int significant_digits = 0; + int insignificant_digits = 0; + bool nonzero_digit_dropped = false; + + bool sign = false; + + if (*current == '+' || *current == '-') { + sign = (*current == '-'); + ++current; + const char* next_non_space = current; + // Skip following spaces (if allowed). + if (!AdvanceToNonspace(&next_non_space, end)) return junk_string_value_; + if (!allow_spaces_after_sign && (current != next_non_space)) { + return junk_string_value_; + } + current = next_non_space; + } + + if (infinity_symbol_ != NULL) { + if (*current == infinity_symbol_[0]) { + if (!ConsumeSubString(¤t, end, infinity_symbol_)) { + return junk_string_value_; + } + + if (!(allow_trailing_spaces || allow_trailing_junk) && (current != end)) { + return junk_string_value_; + } + if (!allow_trailing_junk && AdvanceToNonspace(¤t, end)) { + return junk_string_value_; + } + + ASSERT(buffer_pos == 0); + *processed_characters_count = current - input; + return sign ? -Double::Infinity() : Double::Infinity(); + } + } + + if (nan_symbol_ != NULL) { + if (*current == nan_symbol_[0]) { + if (!ConsumeSubString(¤t, end, nan_symbol_)) { + return junk_string_value_; + } + + if (!(allow_trailing_spaces || allow_trailing_junk) && (current != end)) { + return junk_string_value_; + } + if (!allow_trailing_junk && AdvanceToNonspace(¤t, end)) { + return junk_string_value_; + } + + ASSERT(buffer_pos == 0); + *processed_characters_count = current - input; + return sign ? -Double::NaN() : Double::NaN(); + } + } + + bool leading_zero = false; + if (*current == '0') { + ++current; + if (current == end) { + *processed_characters_count = current - input; + return SignedZero(sign); + } + + leading_zero = true; + + // It could be hexadecimal value. + if ((flags_ & ALLOW_HEX) && (*current == 'x' || *current == 'X')) { + ++current; + if (current == end || !isDigit(*current, 16)) { + return junk_string_value_; // "0x". + } + + const char* tail_pointer = NULL; + double result = RadixStringToIeee<4>(current, + end, + sign, + allow_trailing_junk, + junk_string_value_, + read_as_double, + &tail_pointer); + if (tail_pointer != NULL) { + if (allow_trailing_spaces) AdvanceToNonspace(&tail_pointer, end); + *processed_characters_count = tail_pointer - input; + } + return result; + } + + // Ignore leading zeros in the integer part. + while (*current == '0') { + ++current; + if (current == end) { + *processed_characters_count = current - input; + return SignedZero(sign); + } + } + } + + bool octal = leading_zero && (flags_ & ALLOW_OCTALS) != 0; + + // Copy significant digits of the integer part (if any) to the buffer. + while (*current >= '0' && *current <= '9') { + if (significant_digits < kMaxSignificantDigits) { + ASSERT(buffer_pos < kBufferSize); + buffer[buffer_pos++] = static_cast(*current); + significant_digits++; + // Will later check if it's an octal in the buffer. + } else { + insignificant_digits++; // Move the digit into the exponential part. + nonzero_digit_dropped = nonzero_digit_dropped || *current != '0'; + } + octal = octal && *current < '8'; + ++current; + if (current == end) goto parsing_done; + } + + if (significant_digits == 0) { + octal = false; + } + + if (*current == '.') { + if (octal && !allow_trailing_junk) return junk_string_value_; + if (octal) goto parsing_done; + + ++current; + if (current == end) { + if (significant_digits == 0 && !leading_zero) { + return junk_string_value_; + } else { + goto parsing_done; + } + } + + if (significant_digits == 0) { + // octal = false; + // Integer part consists of 0 or is absent. Significant digits start after + // leading zeros (if any). + while (*current == '0') { + ++current; + if (current == end) { + *processed_characters_count = current - input; + return SignedZero(sign); + } + exponent--; // Move this 0 into the exponent. + } + } + + // There is a fractional part. + // We don't emit a '.', but adjust the exponent instead. + while (*current >= '0' && *current <= '9') { + if (significant_digits < kMaxSignificantDigits) { + ASSERT(buffer_pos < kBufferSize); + buffer[buffer_pos++] = static_cast(*current); + significant_digits++; + exponent--; + } else { + // Ignore insignificant digits in the fractional part. + nonzero_digit_dropped = nonzero_digit_dropped || *current != '0'; + } + ++current; + if (current == end) goto parsing_done; + } + } + + if (!leading_zero && exponent == 0 && significant_digits == 0) { + // If leading_zeros is true then the string contains zeros. + // If exponent < 0 then string was [+-]\.0*... + // If significant_digits != 0 the string is not equal to 0. + // Otherwise there are no digits in the string. + return junk_string_value_; + } + + // Parse exponential part. + if (*current == 'e' || *current == 'E') { + if (octal && !allow_trailing_junk) return junk_string_value_; + if (octal) goto parsing_done; + ++current; + if (current == end) { + if (allow_trailing_junk) { + goto parsing_done; + } else { + return junk_string_value_; + } + } + char sign = '+'; + if (*current == '+' || *current == '-') { + sign = static_cast(*current); + ++current; + if (current == end) { + if (allow_trailing_junk) { + goto parsing_done; + } else { + return junk_string_value_; + } + } + } + + if (current == end || *current < '0' || *current > '9') { + if (allow_trailing_junk) { + goto parsing_done; + } else { + return junk_string_value_; + } + } + + const int max_exponent = INT_MAX / 2; + ASSERT(-max_exponent / 2 <= exponent && exponent <= max_exponent / 2); + int num = 0; + do { + // Check overflow. + int digit = *current - '0'; + if (num >= max_exponent / 10 + && !(num == max_exponent / 10 && digit <= max_exponent % 10)) { + num = max_exponent; + } else { + num = num * 10 + digit; + } + ++current; + } while (current != end && *current >= '0' && *current <= '9'); + + exponent += (sign == '-' ? -num : num); + } + + if (!(allow_trailing_spaces || allow_trailing_junk) && (current != end)) { + return junk_string_value_; + } + if (!allow_trailing_junk && AdvanceToNonspace(¤t, end)) { + return junk_string_value_; + } + if (allow_trailing_spaces) { + AdvanceToNonspace(¤t, end); + } + + parsing_done: + exponent += insignificant_digits; + + if (octal) { + double result; + const char* tail_pointer = NULL; + result = RadixStringToIeee<3>(buffer, + buffer + buffer_pos, + sign, + allow_trailing_junk, + junk_string_value_, + read_as_double, + &tail_pointer); + ASSERT(tail_pointer != NULL); + *processed_characters_count = current - input; + return result; + } + + if (nonzero_digit_dropped) { + buffer[buffer_pos++] = '1'; + exponent--; + } + + ASSERT(buffer_pos < kBufferSize); + buffer[buffer_pos] = '\0'; + + double converted; + if (read_as_double) { + converted = Strtod(Vector(buffer, buffer_pos), exponent); + } else { + converted = Strtof(Vector(buffer, buffer_pos), exponent); + } + *processed_characters_count = current - input; + return sign? -converted: converted; +} + +} // namespace double_conversion diff --git a/mfbt/double-conversion/double-conversion.h b/mfbt/double-conversion/double-conversion.h new file mode 100644 index 000000000000..3401c1e9c7aa --- /dev/null +++ b/mfbt/double-conversion/double-conversion.h @@ -0,0 +1,537 @@ +// Copyright 2012 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_ +#define DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_ + +#include "mozilla/Types.h" +#include "utils.h" + +namespace double_conversion { + +class DoubleToStringConverter { + public: + // When calling ToFixed with a double > 10^kMaxFixedDigitsBeforePoint + // or a requested_digits parameter > kMaxFixedDigitsAfterPoint then the + // function returns false. + static const int kMaxFixedDigitsBeforePoint = 60; + static const int kMaxFixedDigitsAfterPoint = 60; + + // When calling ToExponential with a requested_digits + // parameter > kMaxExponentialDigits then the function returns false. + static const int kMaxExponentialDigits = 120; + + // When calling ToPrecision with a requested_digits + // parameter < kMinPrecisionDigits or requested_digits > kMaxPrecisionDigits + // then the function returns false. + static const int kMinPrecisionDigits = 1; + static const int kMaxPrecisionDigits = 120; + + enum Flags { + NO_FLAGS = 0, + EMIT_POSITIVE_EXPONENT_SIGN = 1, + EMIT_TRAILING_DECIMAL_POINT = 2, + EMIT_TRAILING_ZERO_AFTER_POINT = 4, + UNIQUE_ZERO = 8 + }; + + // Flags should be a bit-or combination of the possible Flags-enum. + // - NO_FLAGS: no special flags. + // - EMIT_POSITIVE_EXPONENT_SIGN: when the number is converted into exponent + // form, emits a '+' for positive exponents. Example: 1.2e+2. + // - EMIT_TRAILING_DECIMAL_POINT: when the input number is an integer and is + // converted into decimal format then a trailing decimal point is appended. + // Example: 2345.0 is converted to "2345.". + // - EMIT_TRAILING_ZERO_AFTER_POINT: in addition to a trailing decimal point + // emits a trailing '0'-character. This flag requires the + // EXMIT_TRAILING_DECIMAL_POINT flag. + // Example: 2345.0 is converted to "2345.0". + // - UNIQUE_ZERO: "-0.0" is converted to "0.0". + // + // Infinity symbol and nan_symbol provide the string representation for these + // special values. If the string is NULL and the special value is encountered + // then the conversion functions return false. + // + // The exponent_character is used in exponential representations. It is + // usually 'e' or 'E'. + // + // When converting to the shortest representation the converter will + // represent input numbers in decimal format if they are in the interval + // [10^decimal_in_shortest_low; 10^decimal_in_shortest_high[ + // (lower boundary included, greater boundary excluded). + // Example: with decimal_in_shortest_low = -6 and + // decimal_in_shortest_high = 21: + // ToShortest(0.000001) -> "0.000001" + // ToShortest(0.0000001) -> "1e-7" + // ToShortest(111111111111111111111.0) -> "111111111111111110000" + // ToShortest(100000000000000000000.0) -> "100000000000000000000" + // ToShortest(1111111111111111111111.0) -> "1.1111111111111111e+21" + // + // When converting to precision mode the converter may add + // max_leading_padding_zeroes before returning the number in exponential + // format. + // Example with max_leading_padding_zeroes_in_precision_mode = 6. + // ToPrecision(0.0000012345, 2) -> "0.0000012" + // ToPrecision(0.00000012345, 2) -> "1.2e-7" + // Similarily the converter may add up to + // max_trailing_padding_zeroes_in_precision_mode in precision mode to avoid + // returning an exponential representation. A zero added by the + // EMIT_TRAILING_ZERO_AFTER_POINT flag is counted for this limit. + // Examples for max_trailing_padding_zeroes_in_precision_mode = 1: + // ToPrecision(230.0, 2) -> "230" + // ToPrecision(230.0, 2) -> "230." with EMIT_TRAILING_DECIMAL_POINT. + // ToPrecision(230.0, 2) -> "2.3e2" with EMIT_TRAILING_ZERO_AFTER_POINT. + DoubleToStringConverter(int flags, + const char* infinity_symbol, + const char* nan_symbol, + char exponent_character, + int decimal_in_shortest_low, + int decimal_in_shortest_high, + int max_leading_padding_zeroes_in_precision_mode, + int max_trailing_padding_zeroes_in_precision_mode) + : flags_(flags), + infinity_symbol_(infinity_symbol), + nan_symbol_(nan_symbol), + exponent_character_(exponent_character), + decimal_in_shortest_low_(decimal_in_shortest_low), + decimal_in_shortest_high_(decimal_in_shortest_high), + max_leading_padding_zeroes_in_precision_mode_( + max_leading_padding_zeroes_in_precision_mode), + max_trailing_padding_zeroes_in_precision_mode_( + max_trailing_padding_zeroes_in_precision_mode) { + // When 'trailing zero after the point' is set, then 'trailing point' + // must be set too. + ASSERT(((flags & EMIT_TRAILING_DECIMAL_POINT) != 0) || + !((flags & EMIT_TRAILING_ZERO_AFTER_POINT) != 0)); + } + + // Returns a converter following the EcmaScript specification. + static MFBT_API(const DoubleToStringConverter&) EcmaScriptConverter(); + + // Computes the shortest string of digits that correctly represent the input + // number. Depending on decimal_in_shortest_low and decimal_in_shortest_high + // (see constructor) it then either returns a decimal representation, or an + // exponential representation. + // Example with decimal_in_shortest_low = -6, + // decimal_in_shortest_high = 21, + // EMIT_POSITIVE_EXPONENT_SIGN activated, and + // EMIT_TRAILING_DECIMAL_POINT deactived: + // ToShortest(0.000001) -> "0.000001" + // ToShortest(0.0000001) -> "1e-7" + // ToShortest(111111111111111111111.0) -> "111111111111111110000" + // ToShortest(100000000000000000000.0) -> "100000000000000000000" + // ToShortest(1111111111111111111111.0) -> "1.1111111111111111e+21" + // + // Note: the conversion may round the output if the returned string + // is accurate enough to uniquely identify the input-number. + // For example the most precise representation of the double 9e59 equals + // "899999999999999918767229449717619953810131273674690656206848", but + // the converter will return the shorter (but still correct) "9e59". + // + // Returns true if the conversion succeeds. The conversion always succeeds + // except when the input value is special and no infinity_symbol or + // nan_symbol has been given to the constructor. + MFBT_API(bool) ToShortest(double value, StringBuilder* result_builder) const { + return ToShortestIeeeNumber(value, result_builder, SHORTEST); + } + + // Same as ToShortest, but for single-precision floats. + MFBT_API(bool) ToShortestSingle(float value, StringBuilder* result_builder) const { + return ToShortestIeeeNumber(value, result_builder, SHORTEST_SINGLE); + } + + + // Computes a decimal representation with a fixed number of digits after the + // decimal point. The last emitted digit is rounded. + // + // Examples: + // ToFixed(3.12, 1) -> "3.1" + // ToFixed(3.1415, 3) -> "3.142" + // ToFixed(1234.56789, 4) -> "1234.5679" + // ToFixed(1.23, 5) -> "1.23000" + // ToFixed(0.1, 4) -> "0.1000" + // ToFixed(1e30, 2) -> "1000000000000000019884624838656.00" + // ToFixed(0.1, 30) -> "0.100000000000000005551115123126" + // ToFixed(0.1, 17) -> "0.10000000000000001" + // + // If requested_digits equals 0, then the tail of the result depends on + // the EMIT_TRAILING_DECIMAL_POINT and EMIT_TRAILING_ZERO_AFTER_POINT. + // Examples, for requested_digits == 0, + // let EMIT_TRAILING_DECIMAL_POINT and EMIT_TRAILING_ZERO_AFTER_POINT be + // - false and false: then 123.45 -> 123 + // 0.678 -> 1 + // - true and false: then 123.45 -> 123. + // 0.678 -> 1. + // - true and true: then 123.45 -> 123.0 + // 0.678 -> 1.0 + // + // Returns true if the conversion succeeds. The conversion always succeeds + // except for the following cases: + // - the input value is special and no infinity_symbol or nan_symbol has + // been provided to the constructor, + // - 'value' > 10^kMaxFixedDigitsBeforePoint, or + // - 'requested_digits' > kMaxFixedDigitsAfterPoint. + // The last two conditions imply that the result will never contain more than + // 1 + kMaxFixedDigitsBeforePoint + 1 + kMaxFixedDigitsAfterPoint characters + // (one additional character for the sign, and one for the decimal point). + MFBT_API(bool) ToFixed(double value, + int requested_digits, + StringBuilder* result_builder) const; + + // Computes a representation in exponential format with requested_digits + // after the decimal point. The last emitted digit is rounded. + // If requested_digits equals -1, then the shortest exponential representation + // is computed. + // + // Examples with EMIT_POSITIVE_EXPONENT_SIGN deactivated, and + // exponent_character set to 'e'. + // ToExponential(3.12, 1) -> "3.1e0" + // ToExponential(5.0, 3) -> "5.000e0" + // ToExponential(0.001, 2) -> "1.00e-3" + // ToExponential(3.1415, -1) -> "3.1415e0" + // ToExponential(3.1415, 4) -> "3.1415e0" + // ToExponential(3.1415, 3) -> "3.142e0" + // ToExponential(123456789000000, 3) -> "1.235e14" + // ToExponential(1000000000000000019884624838656.0, -1) -> "1e30" + // ToExponential(1000000000000000019884624838656.0, 32) -> + // "1.00000000000000001988462483865600e30" + // ToExponential(1234, 0) -> "1e3" + // + // Returns true if the conversion succeeds. The conversion always succeeds + // except for the following cases: + // - the input value is special and no infinity_symbol or nan_symbol has + // been provided to the constructor, + // - 'requested_digits' > kMaxExponentialDigits. + // The last condition implies that the result will never contain more than + // kMaxExponentialDigits + 8 characters (the sign, the digit before the + // decimal point, the decimal point, the exponent character, the + // exponent's sign, and at most 3 exponent digits). + MFBT_API(bool) ToExponential(double value, + int requested_digits, + StringBuilder* result_builder) const; + + // Computes 'precision' leading digits of the given 'value' and returns them + // either in exponential or decimal format, depending on + // max_{leading|trailing}_padding_zeroes_in_precision_mode (given to the + // constructor). + // The last computed digit is rounded. + // + // Example with max_leading_padding_zeroes_in_precision_mode = 6. + // ToPrecision(0.0000012345, 2) -> "0.0000012" + // ToPrecision(0.00000012345, 2) -> "1.2e-7" + // Similarily the converter may add up to + // max_trailing_padding_zeroes_in_precision_mode in precision mode to avoid + // returning an exponential representation. A zero added by the + // EMIT_TRAILING_ZERO_AFTER_POINT flag is counted for this limit. + // Examples for max_trailing_padding_zeroes_in_precision_mode = 1: + // ToPrecision(230.0, 2) -> "230" + // ToPrecision(230.0, 2) -> "230." with EMIT_TRAILING_DECIMAL_POINT. + // ToPrecision(230.0, 2) -> "2.3e2" with EMIT_TRAILING_ZERO_AFTER_POINT. + // Examples for max_trailing_padding_zeroes_in_precision_mode = 3, and no + // EMIT_TRAILING_ZERO_AFTER_POINT: + // ToPrecision(123450.0, 6) -> "123450" + // ToPrecision(123450.0, 5) -> "123450" + // ToPrecision(123450.0, 4) -> "123500" + // ToPrecision(123450.0, 3) -> "123000" + // ToPrecision(123450.0, 2) -> "1.2e5" + // + // Returns true if the conversion succeeds. The conversion always succeeds + // except for the following cases: + // - the input value is special and no infinity_symbol or nan_symbol has + // been provided to the constructor, + // - precision < kMinPericisionDigits + // - precision > kMaxPrecisionDigits + // The last condition implies that the result will never contain more than + // kMaxPrecisionDigits + 7 characters (the sign, the decimal point, the + // exponent character, the exponent's sign, and at most 3 exponent digits). + MFBT_API(bool) ToPrecision(double value, + int precision, + StringBuilder* result_builder) const; + + enum DtoaMode { + // Produce the shortest correct representation. + // For example the output of 0.299999999999999988897 is (the less accurate + // but correct) 0.3. + SHORTEST, + // Same as SHORTEST, but for single-precision floats. + SHORTEST_SINGLE, + // Produce a fixed number of digits after the decimal point. + // For instance fixed(0.1, 4) becomes 0.1000 + // If the input number is big, the output will be big. + FIXED, + // Fixed number of digits (independent of the decimal point). + PRECISION + }; + + // The maximal number of digits that are needed to emit a double in base 10. + // A higher precision can be achieved by using more digits, but the shortest + // accurate representation of any double will never use more digits than + // kBase10MaximalLength. + // Note that DoubleToAscii null-terminates its input. So the given buffer + // should be at least kBase10MaximalLength + 1 characters long. + static const MFBT_DATA(int) kBase10MaximalLength = 17; + + // Converts the given double 'v' to ascii. 'v' must not be NaN, +Infinity, or + // -Infinity. In SHORTEST_SINGLE-mode this restriction also applies to 'v' + // after it has been casted to a single-precision float. That is, in this + // mode static_cast(v) must not be NaN, +Infinity or -Infinity. + // + // The result should be interpreted as buffer * 10^(point-length). + // + // The output depends on the given mode: + // - SHORTEST: produce the least amount of digits for which the internal + // identity requirement is still satisfied. If the digits are printed + // (together with the correct exponent) then reading this number will give + // 'v' again. The buffer will choose the representation that is closest to + // 'v'. If there are two at the same distance, than the one farther away + // from 0 is chosen (halfway cases - ending with 5 - are rounded up). + // In this mode the 'requested_digits' parameter is ignored. + // - SHORTEST_SINGLE: same as SHORTEST but with single-precision. + // - FIXED: produces digits necessary to print a given number with + // 'requested_digits' digits after the decimal point. The produced digits + // might be too short in which case the caller has to fill the remainder + // with '0's. + // Example: toFixed(0.001, 5) is allowed to return buffer="1", point=-2. + // Halfway cases are rounded towards +/-Infinity (away from 0). The call + // toFixed(0.15, 2) thus returns buffer="2", point=0. + // The returned buffer may contain digits that would be truncated from the + // shortest representation of the input. + // - PRECISION: produces 'requested_digits' where the first digit is not '0'. + // Even though the length of produced digits usually equals + // 'requested_digits', the function is allowed to return fewer digits, in + // which case the caller has to fill the missing digits with '0's. + // Halfway cases are again rounded away from 0. + // DoubleToAscii expects the given buffer to be big enough to hold all + // digits and a terminating null-character. In SHORTEST-mode it expects a + // buffer of at least kBase10MaximalLength + 1. In all other modes the + // requested_digits parameter and the padding-zeroes limit the size of the + // output. Don't forget the decimal point, the exponent character and the + // terminating null-character when computing the maximal output size. + // The given length is only used in debug mode to ensure the buffer is big + // enough. + static MFBT_API(void) DoubleToAscii(double v, + DtoaMode mode, + int requested_digits, + char* buffer, + int buffer_length, + bool* sign, + int* length, + int* point); + + private: + // Implementation for ToShortest and ToShortestSingle. + MFBT_API(bool) ToShortestIeeeNumber(double value, + StringBuilder* result_builder, + DtoaMode mode) const; + + // If the value is a special value (NaN or Infinity) constructs the + // corresponding string using the configured infinity/nan-symbol. + // If either of them is NULL or the value is not special then the + // function returns false. + MFBT_API(bool) HandleSpecialValues(double value, StringBuilder* result_builder) const; + // Constructs an exponential representation (i.e. 1.234e56). + // The given exponent assumes a decimal point after the first decimal digit. + MFBT_API(void) CreateExponentialRepresentation(const char* decimal_digits, + int length, + int exponent, + StringBuilder* result_builder) const; + // Creates a decimal representation (i.e 1234.5678). + MFBT_API(void) CreateDecimalRepresentation(const char* decimal_digits, + int length, + int decimal_point, + int digits_after_point, + StringBuilder* result_builder) const; + + const int flags_; + const char* const infinity_symbol_; + const char* const nan_symbol_; + const char exponent_character_; + const int decimal_in_shortest_low_; + const int decimal_in_shortest_high_; + const int max_leading_padding_zeroes_in_precision_mode_; + const int max_trailing_padding_zeroes_in_precision_mode_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(DoubleToStringConverter); +}; + + +class StringToDoubleConverter { + public: + // Enumeration for allowing octals and ignoring junk when converting + // strings to numbers. + enum Flags { + NO_FLAGS = 0, + ALLOW_HEX = 1, + ALLOW_OCTALS = 2, + ALLOW_TRAILING_JUNK = 4, + ALLOW_LEADING_SPACES = 8, + ALLOW_TRAILING_SPACES = 16, + ALLOW_SPACES_AFTER_SIGN = 32 + }; + + // Flags should be a bit-or combination of the possible Flags-enum. + // - NO_FLAGS: no special flags. + // - ALLOW_HEX: recognizes the prefix "0x". Hex numbers may only be integers. + // Ex: StringToDouble("0x1234") -> 4660.0 + // In StringToDouble("0x1234.56") the characters ".56" are trailing + // junk. The result of the call is hence dependent on + // the ALLOW_TRAILING_JUNK flag and/or the junk value. + // With this flag "0x" is a junk-string. Even with ALLOW_TRAILING_JUNK, + // the string will not be parsed as "0" followed by junk. + // + // - ALLOW_OCTALS: recognizes the prefix "0" for octals: + // If a sequence of octal digits starts with '0', then the number is + // read as octal integer. Octal numbers may only be integers. + // Ex: StringToDouble("01234") -> 668.0 + // StringToDouble("012349") -> 12349.0 // Not a sequence of octal + // // digits. + // In StringToDouble("01234.56") the characters ".56" are trailing + // junk. The result of the call is hence dependent on + // the ALLOW_TRAILING_JUNK flag and/or the junk value. + // In StringToDouble("01234e56") the characters "e56" are trailing + // junk, too. + // - ALLOW_TRAILING_JUNK: ignore trailing characters that are not part of + // a double literal. + // - ALLOW_LEADING_SPACES: skip over leading spaces. + // - ALLOW_TRAILING_SPACES: ignore trailing spaces. + // - ALLOW_SPACES_AFTER_SIGN: ignore spaces after the sign. + // Ex: StringToDouble("- 123.2") -> -123.2. + // StringToDouble("+ 123.2") -> 123.2 + // + // empty_string_value is returned when an empty string is given as input. + // If ALLOW_LEADING_SPACES or ALLOW_TRAILING_SPACES are set, then a string + // containing only spaces is converted to the 'empty_string_value', too. + // + // junk_string_value is returned when + // a) ALLOW_TRAILING_JUNK is not set, and a junk character (a character not + // part of a double-literal) is found. + // b) ALLOW_TRAILING_JUNK is set, but the string does not start with a + // double literal. + // + // infinity_symbol and nan_symbol are strings that are used to detect + // inputs that represent infinity and NaN. They can be null, in which case + // they are ignored. + // The conversion routine first reads any possible signs. Then it compares the + // following character of the input-string with the first character of + // the infinity, and nan-symbol. If either matches, the function assumes, that + // a match has been found, and expects the following input characters to match + // the remaining characters of the special-value symbol. + // This means that the following restrictions apply to special-value symbols: + // - they must not start with signs ('+', or '-'), + // - they must not have the same first character. + // - they must not start with digits. + // + // Examples: + // flags = ALLOW_HEX | ALLOW_TRAILING_JUNK, + // empty_string_value = 0.0, + // junk_string_value = NaN, + // infinity_symbol = "infinity", + // nan_symbol = "nan": + // StringToDouble("0x1234") -> 4660.0. + // StringToDouble("0x1234K") -> 4660.0. + // StringToDouble("") -> 0.0 // empty_string_value. + // StringToDouble(" ") -> NaN // junk_string_value. + // StringToDouble(" 1") -> NaN // junk_string_value. + // StringToDouble("0x") -> NaN // junk_string_value. + // StringToDouble("-123.45") -> -123.45. + // StringToDouble("--123.45") -> NaN // junk_string_value. + // StringToDouble("123e45") -> 123e45. + // StringToDouble("123E45") -> 123e45. + // StringToDouble("123e+45") -> 123e45. + // StringToDouble("123E-45") -> 123e-45. + // StringToDouble("123e") -> 123.0 // trailing junk ignored. + // StringToDouble("123e-") -> 123.0 // trailing junk ignored. + // StringToDouble("+NaN") -> NaN // NaN string literal. + // StringToDouble("-infinity") -> -inf. // infinity literal. + // StringToDouble("Infinity") -> NaN // junk_string_value. + // + // flags = ALLOW_OCTAL | ALLOW_LEADING_SPACES, + // empty_string_value = 0.0, + // junk_string_value = NaN, + // infinity_symbol = NULL, + // nan_symbol = NULL: + // StringToDouble("0x1234") -> NaN // junk_string_value. + // StringToDouble("01234") -> 668.0. + // StringToDouble("") -> 0.0 // empty_string_value. + // StringToDouble(" ") -> 0.0 // empty_string_value. + // StringToDouble(" 1") -> 1.0 + // StringToDouble("0x") -> NaN // junk_string_value. + // StringToDouble("0123e45") -> NaN // junk_string_value. + // StringToDouble("01239E45") -> 1239e45. + // StringToDouble("-infinity") -> NaN // junk_string_value. + // StringToDouble("NaN") -> NaN // junk_string_value. + StringToDoubleConverter(int flags, + double empty_string_value, + double junk_string_value, + const char* infinity_symbol, + const char* nan_symbol) + : flags_(flags), + empty_string_value_(empty_string_value), + junk_string_value_(junk_string_value), + infinity_symbol_(infinity_symbol), + nan_symbol_(nan_symbol) { + } + + // Performs the conversion. + // The output parameter 'processed_characters_count' is set to the number + // of characters that have been processed to read the number. + // Spaces than are processed with ALLOW_{LEADING|TRAILING}_SPACES are included + // in the 'processed_characters_count'. Trailing junk is never included. + double StringToDouble(const char* buffer, + int length, + int* processed_characters_count) { + return StringToIeee(buffer, length, processed_characters_count, true); + } + + // Same as StringToDouble but reads a float. + // Note that this is not equivalent to static_cast(StringToDouble(...)) + // due to potential double-rounding. + float StringToFloat(const char* buffer, + int length, + int* processed_characters_count) { + return static_cast(StringToIeee(buffer, length, + processed_characters_count, false)); + } + + private: + const int flags_; + const double empty_string_value_; + const double junk_string_value_; + const char* const infinity_symbol_; + const char* const nan_symbol_; + + double StringToIeee(const char* buffer, + int length, + int* processed_characters_count, + bool read_as_double); + + DISALLOW_IMPLICIT_CONSTRUCTORS(StringToDoubleConverter); +}; + +} // namespace double_conversion + +#endif // DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_ diff --git a/mfbt/double-conversion/fast-dtoa.cc b/mfbt/double-conversion/fast-dtoa.cc new file mode 100644 index 000000000000..0609422798a9 --- /dev/null +++ b/mfbt/double-conversion/fast-dtoa.cc @@ -0,0 +1,664 @@ +// Copyright 2012 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "fast-dtoa.h" + +#include "cached-powers.h" +#include "diy-fp.h" +#include "ieee.h" + +namespace double_conversion { + +// The minimal and maximal target exponent define the range of w's binary +// exponent, where 'w' is the result of multiplying the input by a cached power +// of ten. +// +// A different range might be chosen on a different platform, to optimize digit +// generation, but a smaller range requires more powers of ten to be cached. +static const int kMinimalTargetExponent = -60; +static const int kMaximalTargetExponent = -32; + + +// Adjusts the last digit of the generated number, and screens out generated +// solutions that may be inaccurate. A solution may be inaccurate if it is +// outside the safe interval, or if we cannot prove that it is closer to the +// input than a neighboring representation of the same length. +// +// Input: * buffer containing the digits of too_high / 10^kappa +// * the buffer's length +// * distance_too_high_w == (too_high - w).f() * unit +// * unsafe_interval == (too_high - too_low).f() * unit +// * rest = (too_high - buffer * 10^kappa).f() * unit +// * ten_kappa = 10^kappa * unit +// * unit = the common multiplier +// Output: returns true if the buffer is guaranteed to contain the closest +// representable number to the input. +// Modifies the generated digits in the buffer to approach (round towards) w. +static bool RoundWeed(Vector buffer, + int length, + uint64_t distance_too_high_w, + uint64_t unsafe_interval, + uint64_t rest, + uint64_t ten_kappa, + uint64_t unit) { + uint64_t small_distance = distance_too_high_w - unit; + uint64_t big_distance = distance_too_high_w + unit; + // Let w_low = too_high - big_distance, and + // w_high = too_high - small_distance. + // Note: w_low < w < w_high + // + // The real w (* unit) must lie somewhere inside the interval + // ]w_low; w_high[ (often written as "(w_low; w_high)") + + // Basically the buffer currently contains a number in the unsafe interval + // ]too_low; too_high[ with too_low < w < too_high + // + // too_high - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // ^v 1 unit ^ ^ ^ ^ + // boundary_high --------------------- . . . . + // ^v 1 unit . . . . + // - - - - - - - - - - - - - - - - - - - + - - + - - - - - - . . + // . . ^ . . + // . big_distance . . . + // . . . . rest + // small_distance . . . . + // v . . . . + // w_high - - - - - - - - - - - - - - - - - - . . . . + // ^v 1 unit . . . . + // w ---------------------------------------- . . . . + // ^v 1 unit v . . . + // w_low - - - - - - - - - - - - - - - - - - - - - . . . + // . . v + // buffer --------------------------------------------------+-------+-------- + // . . + // safe_interval . + // v . + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - . + // ^v 1 unit . + // boundary_low ------------------------- unsafe_interval + // ^v 1 unit v + // too_low - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // + // + // Note that the value of buffer could lie anywhere inside the range too_low + // to too_high. + // + // boundary_low, boundary_high and w are approximations of the real boundaries + // and v (the input number). They are guaranteed to be precise up to one unit. + // In fact the error is guaranteed to be strictly less than one unit. + // + // Anything that lies outside the unsafe interval is guaranteed not to round + // to v when read again. + // Anything that lies inside the safe interval is guaranteed to round to v + // when read again. + // If the number inside the buffer lies inside the unsafe interval but not + // inside the safe interval then we simply do not know and bail out (returning + // false). + // + // Similarly we have to take into account the imprecision of 'w' when finding + // the closest representation of 'w'. If we have two potential + // representations, and one is closer to both w_low and w_high, then we know + // it is closer to the actual value v. + // + // By generating the digits of too_high we got the largest (closest to + // too_high) buffer that is still in the unsafe interval. In the case where + // w_high < buffer < too_high we try to decrement the buffer. + // This way the buffer approaches (rounds towards) w. + // There are 3 conditions that stop the decrementation process: + // 1) the buffer is already below w_high + // 2) decrementing the buffer would make it leave the unsafe interval + // 3) decrementing the buffer would yield a number below w_high and farther + // away than the current number. In other words: + // (buffer{-1} < w_high) && w_high - buffer{-1} > buffer - w_high + // Instead of using the buffer directly we use its distance to too_high. + // Conceptually rest ~= too_high - buffer + // We need to do the following tests in this order to avoid over- and + // underflows. + ASSERT(rest <= unsafe_interval); + while (rest < small_distance && // Negated condition 1 + unsafe_interval - rest >= ten_kappa && // Negated condition 2 + (rest + ten_kappa < small_distance || // buffer{-1} > w_high + small_distance - rest >= rest + ten_kappa - small_distance)) { + buffer[length - 1]--; + rest += ten_kappa; + } + + // We have approached w+ as much as possible. We now test if approaching w- + // would require changing the buffer. If yes, then we have two possible + // representations close to w, but we cannot decide which one is closer. + if (rest < big_distance && + unsafe_interval - rest >= ten_kappa && + (rest + ten_kappa < big_distance || + big_distance - rest > rest + ten_kappa - big_distance)) { + return false; + } + + // Weeding test. + // The safe interval is [too_low + 2 ulp; too_high - 2 ulp] + // Since too_low = too_high - unsafe_interval this is equivalent to + // [too_high - unsafe_interval + 4 ulp; too_high - 2 ulp] + // Conceptually we have: rest ~= too_high - buffer + return (2 * unit <= rest) && (rest <= unsafe_interval - 4 * unit); +} + + +// Rounds the buffer upwards if the result is closer to v by possibly adding +// 1 to the buffer. If the precision of the calculation is not sufficient to +// round correctly, return false. +// The rounding might shift the whole buffer in which case the kappa is +// adjusted. For example "99", kappa = 3 might become "10", kappa = 4. +// +// If 2*rest > ten_kappa then the buffer needs to be round up. +// rest can have an error of +/- 1 unit. This function accounts for the +// imprecision and returns false, if the rounding direction cannot be +// unambiguously determined. +// +// Precondition: rest < ten_kappa. +static bool RoundWeedCounted(Vector buffer, + int length, + uint64_t rest, + uint64_t ten_kappa, + uint64_t unit, + int* kappa) { + ASSERT(rest < ten_kappa); + // The following tests are done in a specific order to avoid overflows. They + // will work correctly with any uint64 values of rest < ten_kappa and unit. + // + // If the unit is too big, then we don't know which way to round. For example + // a unit of 50 means that the real number lies within rest +/- 50. If + // 10^kappa == 40 then there is no way to tell which way to round. + if (unit >= ten_kappa) return false; + // Even if unit is just half the size of 10^kappa we are already completely + // lost. (And after the previous test we know that the expression will not + // over/underflow.) + if (ten_kappa - unit <= unit) return false; + // If 2 * (rest + unit) <= 10^kappa we can safely round down. + if ((ten_kappa - rest > rest) && (ten_kappa - 2 * rest >= 2 * unit)) { + return true; + } + // If 2 * (rest - unit) >= 10^kappa, then we can safely round up. + if ((rest > unit) && (ten_kappa - (rest - unit) <= (rest - unit))) { + // Increment the last digit recursively until we find a non '9' digit. + buffer[length - 1]++; + for (int i = length - 1; i > 0; --i) { + if (buffer[i] != '0' + 10) break; + buffer[i] = '0'; + buffer[i - 1]++; + } + // If the first digit is now '0'+ 10 we had a buffer with all '9's. With the + // exception of the first digit all digits are now '0'. Simply switch the + // first digit to '1' and adjust the kappa. Example: "99" becomes "10" and + // the power (the kappa) is increased. + if (buffer[0] == '0' + 10) { + buffer[0] = '1'; + (*kappa) += 1; + } + return true; + } + return false; +} + +// Returns the biggest power of ten that is less than or equal to the given +// number. We furthermore receive the maximum number of bits 'number' has. +// +// Returns power == 10^(exponent_plus_one-1) such that +// power <= number < power * 10. +// If number_bits == 0 then 0^(0-1) is returned. +// The number of bits must be <= 32. +// Precondition: number < (1 << (number_bits + 1)). + +// Inspired by the method for finding an integer log base 10 from here: +// http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10 +static unsigned int const kSmallPowersOfTen[] = + {0, 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, + 1000000000}; + +static void BiggestPowerTen(uint32_t number, + int number_bits, + uint32_t* power, + int* exponent_plus_one) { + ASSERT(number < (1u << (number_bits + 1))); + // 1233/4096 is approximately 1/lg(10). + int exponent_plus_one_guess = ((number_bits + 1) * 1233 >> 12); + // We increment to skip over the first entry in the kPowersOf10 table. + // Note: kPowersOf10[i] == 10^(i-1). + exponent_plus_one_guess++; + // We don't have any guarantees that 2^number_bits <= number. + // TODO(floitsch): can we change the 'while' into an 'if'? We definitely see + // number < (2^number_bits - 1), but I haven't encountered + // number < (2^number_bits - 2) yet. + while (number < kSmallPowersOfTen[exponent_plus_one_guess]) { + exponent_plus_one_guess--; + } + *power = kSmallPowersOfTen[exponent_plus_one_guess]; + *exponent_plus_one = exponent_plus_one_guess; +} + +// Generates the digits of input number w. +// w is a floating-point number (DiyFp), consisting of a significand and an +// exponent. Its exponent is bounded by kMinimalTargetExponent and +// kMaximalTargetExponent. +// Hence -60 <= w.e() <= -32. +// +// Returns false if it fails, in which case the generated digits in the buffer +// should not be used. +// Preconditions: +// * low, w and high are correct up to 1 ulp (unit in the last place). That +// is, their error must be less than a unit of their last digits. +// * low.e() == w.e() == high.e() +// * low < w < high, and taking into account their error: low~ <= high~ +// * kMinimalTargetExponent <= w.e() <= kMaximalTargetExponent +// Postconditions: returns false if procedure fails. +// otherwise: +// * buffer is not null-terminated, but len contains the number of digits. +// * buffer contains the shortest possible decimal digit-sequence +// such that LOW < buffer * 10^kappa < HIGH, where LOW and HIGH are the +// correct values of low and high (without their error). +// * if more than one decimal representation gives the minimal number of +// decimal digits then the one closest to W (where W is the correct value +// of w) is chosen. +// Remark: this procedure takes into account the imprecision of its input +// numbers. If the precision is not enough to guarantee all the postconditions +// then false is returned. This usually happens rarely (~0.5%). +// +// Say, for the sake of example, that +// w.e() == -48, and w.f() == 0x1234567890abcdef +// w's value can be computed by w.f() * 2^w.e() +// We can obtain w's integral digits by simply shifting w.f() by -w.e(). +// -> w's integral part is 0x1234 +// w's fractional part is therefore 0x567890abcdef. +// Printing w's integral part is easy (simply print 0x1234 in decimal). +// In order to print its fraction we repeatedly multiply the fraction by 10 and +// get each digit. Example the first digit after the point would be computed by +// (0x567890abcdef * 10) >> 48. -> 3 +// The whole thing becomes slightly more complicated because we want to stop +// once we have enough digits. That is, once the digits inside the buffer +// represent 'w' we can stop. Everything inside the interval low - high +// represents w. However we have to pay attention to low, high and w's +// imprecision. +static bool DigitGen(DiyFp low, + DiyFp w, + DiyFp high, + Vector buffer, + int* length, + int* kappa) { + ASSERT(low.e() == w.e() && w.e() == high.e()); + ASSERT(low.f() + 1 <= high.f() - 1); + ASSERT(kMinimalTargetExponent <= w.e() && w.e() <= kMaximalTargetExponent); + // low, w and high are imprecise, but by less than one ulp (unit in the last + // place). + // If we remove (resp. add) 1 ulp from low (resp. high) we are certain that + // the new numbers are outside of the interval we want the final + // representation to lie in. + // Inversely adding (resp. removing) 1 ulp from low (resp. high) would yield + // numbers that are certain to lie in the interval. We will use this fact + // later on. + // We will now start by generating the digits within the uncertain + // interval. Later we will weed out representations that lie outside the safe + // interval and thus _might_ lie outside the correct interval. + uint64_t unit = 1; + DiyFp too_low = DiyFp(low.f() - unit, low.e()); + DiyFp too_high = DiyFp(high.f() + unit, high.e()); + // too_low and too_high are guaranteed to lie outside the interval we want the + // generated number in. + DiyFp unsafe_interval = DiyFp::Minus(too_high, too_low); + // We now cut the input number into two parts: the integral digits and the + // fractionals. We will not write any decimal separator though, but adapt + // kappa instead. + // Reminder: we are currently computing the digits (stored inside the buffer) + // such that: too_low < buffer * 10^kappa < too_high + // We use too_high for the digit_generation and stop as soon as possible. + // If we stop early we effectively round down. + DiyFp one = DiyFp(static_cast(1) << -w.e(), w.e()); + // Division by one is a shift. + uint32_t integrals = static_cast(too_high.f() >> -one.e()); + // Modulo by one is an and. + uint64_t fractionals = too_high.f() & (one.f() - 1); + uint32_t divisor; + int divisor_exponent_plus_one; + BiggestPowerTen(integrals, DiyFp::kSignificandSize - (-one.e()), + &divisor, &divisor_exponent_plus_one); + *kappa = divisor_exponent_plus_one; + *length = 0; + // Loop invariant: buffer = too_high / 10^kappa (integer division) + // The invariant holds for the first iteration: kappa has been initialized + // with the divisor exponent + 1. And the divisor is the biggest power of ten + // that is smaller than integrals. + while (*kappa > 0) { + int digit = integrals / divisor; + buffer[*length] = '0' + digit; + (*length)++; + integrals %= divisor; + (*kappa)--; + // Note that kappa now equals the exponent of the divisor and that the + // invariant thus holds again. + uint64_t rest = + (static_cast(integrals) << -one.e()) + fractionals; + // Invariant: too_high = buffer * 10^kappa + DiyFp(rest, one.e()) + // Reminder: unsafe_interval.e() == one.e() + if (rest < unsafe_interval.f()) { + // Rounding down (by not emitting the remaining digits) yields a number + // that lies within the unsafe interval. + return RoundWeed(buffer, *length, DiyFp::Minus(too_high, w).f(), + unsafe_interval.f(), rest, + static_cast(divisor) << -one.e(), unit); + } + divisor /= 10; + } + + // The integrals have been generated. We are at the point of the decimal + // separator. In the following loop we simply multiply the remaining digits by + // 10 and divide by one. We just need to pay attention to multiply associated + // data (like the interval or 'unit'), too. + // Note that the multiplication by 10 does not overflow, because w.e >= -60 + // and thus one.e >= -60. + ASSERT(one.e() >= -60); + ASSERT(fractionals < one.f()); + ASSERT(UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF) / 10 >= one.f()); + while (true) { + fractionals *= 10; + unit *= 10; + unsafe_interval.set_f(unsafe_interval.f() * 10); + // Integer division by one. + int digit = static_cast(fractionals >> -one.e()); + buffer[*length] = '0' + digit; + (*length)++; + fractionals &= one.f() - 1; // Modulo by one. + (*kappa)--; + if (fractionals < unsafe_interval.f()) { + return RoundWeed(buffer, *length, DiyFp::Minus(too_high, w).f() * unit, + unsafe_interval.f(), fractionals, one.f(), unit); + } + } +} + + + +// Generates (at most) requested_digits digits of input number w. +// w is a floating-point number (DiyFp), consisting of a significand and an +// exponent. Its exponent is bounded by kMinimalTargetExponent and +// kMaximalTargetExponent. +// Hence -60 <= w.e() <= -32. +// +// Returns false if it fails, in which case the generated digits in the buffer +// should not be used. +// Preconditions: +// * w is correct up to 1 ulp (unit in the last place). That +// is, its error must be strictly less than a unit of its last digit. +// * kMinimalTargetExponent <= w.e() <= kMaximalTargetExponent +// +// Postconditions: returns false if procedure fails. +// otherwise: +// * buffer is not null-terminated, but length contains the number of +// digits. +// * the representation in buffer is the most precise representation of +// requested_digits digits. +// * buffer contains at most requested_digits digits of w. If there are less +// than requested_digits digits then some trailing '0's have been removed. +// * kappa is such that +// w = buffer * 10^kappa + eps with |eps| < 10^kappa / 2. +// +// Remark: This procedure takes into account the imprecision of its input +// numbers. If the precision is not enough to guarantee all the postconditions +// then false is returned. This usually happens rarely, but the failure-rate +// increases with higher requested_digits. +static bool DigitGenCounted(DiyFp w, + int requested_digits, + Vector buffer, + int* length, + int* kappa) { + ASSERT(kMinimalTargetExponent <= w.e() && w.e() <= kMaximalTargetExponent); + ASSERT(kMinimalTargetExponent >= -60); + ASSERT(kMaximalTargetExponent <= -32); + // w is assumed to have an error less than 1 unit. Whenever w is scaled we + // also scale its error. + uint64_t w_error = 1; + // We cut the input number into two parts: the integral digits and the + // fractional digits. We don't emit any decimal separator, but adapt kappa + // instead. Example: instead of writing "1.2" we put "12" into the buffer and + // increase kappa by 1. + DiyFp one = DiyFp(static_cast(1) << -w.e(), w.e()); + // Division by one is a shift. + uint32_t integrals = static_cast(w.f() >> -one.e()); + // Modulo by one is an and. + uint64_t fractionals = w.f() & (one.f() - 1); + uint32_t divisor; + int divisor_exponent_plus_one; + BiggestPowerTen(integrals, DiyFp::kSignificandSize - (-one.e()), + &divisor, &divisor_exponent_plus_one); + *kappa = divisor_exponent_plus_one; + *length = 0; + + // Loop invariant: buffer = w / 10^kappa (integer division) + // The invariant holds for the first iteration: kappa has been initialized + // with the divisor exponent + 1. And the divisor is the biggest power of ten + // that is smaller than 'integrals'. + while (*kappa > 0) { + int digit = integrals / divisor; + buffer[*length] = '0' + digit; + (*length)++; + requested_digits--; + integrals %= divisor; + (*kappa)--; + // Note that kappa now equals the exponent of the divisor and that the + // invariant thus holds again. + if (requested_digits == 0) break; + divisor /= 10; + } + + if (requested_digits == 0) { + uint64_t rest = + (static_cast(integrals) << -one.e()) + fractionals; + return RoundWeedCounted(buffer, *length, rest, + static_cast(divisor) << -one.e(), w_error, + kappa); + } + + // The integrals have been generated. We are at the point of the decimal + // separator. In the following loop we simply multiply the remaining digits by + // 10 and divide by one. We just need to pay attention to multiply associated + // data (the 'unit'), too. + // Note that the multiplication by 10 does not overflow, because w.e >= -60 + // and thus one.e >= -60. + ASSERT(one.e() >= -60); + ASSERT(fractionals < one.f()); + ASSERT(UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF) / 10 >= one.f()); + while (requested_digits > 0 && fractionals > w_error) { + fractionals *= 10; + w_error *= 10; + // Integer division by one. + int digit = static_cast(fractionals >> -one.e()); + buffer[*length] = '0' + digit; + (*length)++; + requested_digits--; + fractionals &= one.f() - 1; // Modulo by one. + (*kappa)--; + } + if (requested_digits != 0) return false; + return RoundWeedCounted(buffer, *length, fractionals, one.f(), w_error, + kappa); +} + + +// Provides a decimal representation of v. +// Returns true if it succeeds, otherwise the result cannot be trusted. +// There will be *length digits inside the buffer (not null-terminated). +// If the function returns true then +// v == (double) (buffer * 10^decimal_exponent). +// The digits in the buffer are the shortest representation possible: no +// 0.09999999999999999 instead of 0.1. The shorter representation will even be +// chosen even if the longer one would be closer to v. +// The last digit will be closest to the actual v. That is, even if several +// digits might correctly yield 'v' when read again, the closest will be +// computed. +static bool Grisu3(double v, + FastDtoaMode mode, + Vector buffer, + int* length, + int* decimal_exponent) { + DiyFp w = Double(v).AsNormalizedDiyFp(); + // boundary_minus and boundary_plus are the boundaries between v and its + // closest floating-point neighbors. Any number strictly between + // boundary_minus and boundary_plus will round to v when convert to a double. + // Grisu3 will never output representations that lie exactly on a boundary. + DiyFp boundary_minus, boundary_plus; + if (mode == FAST_DTOA_SHORTEST) { + Double(v).NormalizedBoundaries(&boundary_minus, &boundary_plus); + } else { + assert(mode == FAST_DTOA_SHORTEST_SINGLE); + float single_v = static_cast(v); + Single(single_v).NormalizedBoundaries(&boundary_minus, &boundary_plus); + } + ASSERT(boundary_plus.e() == w.e()); + DiyFp ten_mk; // Cached power of ten: 10^-k + int mk; // -k + int ten_mk_minimal_binary_exponent = + kMinimalTargetExponent - (w.e() + DiyFp::kSignificandSize); + int ten_mk_maximal_binary_exponent = + kMaximalTargetExponent - (w.e() + DiyFp::kSignificandSize); + PowersOfTenCache::GetCachedPowerForBinaryExponentRange( + ten_mk_minimal_binary_exponent, + ten_mk_maximal_binary_exponent, + &ten_mk, &mk); + ASSERT((kMinimalTargetExponent <= w.e() + ten_mk.e() + + DiyFp::kSignificandSize) && + (kMaximalTargetExponent >= w.e() + ten_mk.e() + + DiyFp::kSignificandSize)); + // Note that ten_mk is only an approximation of 10^-k. A DiyFp only contains a + // 64 bit significand and ten_mk is thus only precise up to 64 bits. + + // The DiyFp::Times procedure rounds its result, and ten_mk is approximated + // too. The variable scaled_w (as well as scaled_boundary_minus/plus) are now + // off by a small amount. + // In fact: scaled_w - w*10^k < 1ulp (unit in the last place) of scaled_w. + // In other words: let f = scaled_w.f() and e = scaled_w.e(), then + // (f-1) * 2^e < w*10^k < (f+1) * 2^e + DiyFp scaled_w = DiyFp::Times(w, ten_mk); + ASSERT(scaled_w.e() == + boundary_plus.e() + ten_mk.e() + DiyFp::kSignificandSize); + // In theory it would be possible to avoid some recomputations by computing + // the difference between w and boundary_minus/plus (a power of 2) and to + // compute scaled_boundary_minus/plus by subtracting/adding from + // scaled_w. However the code becomes much less readable and the speed + // enhancements are not terriffic. + DiyFp scaled_boundary_minus = DiyFp::Times(boundary_minus, ten_mk); + DiyFp scaled_boundary_plus = DiyFp::Times(boundary_plus, ten_mk); + + // DigitGen will generate the digits of scaled_w. Therefore we have + // v == (double) (scaled_w * 10^-mk). + // Set decimal_exponent == -mk and pass it to DigitGen. If scaled_w is not an + // integer than it will be updated. For instance if scaled_w == 1.23 then + // the buffer will be filled with "123" und the decimal_exponent will be + // decreased by 2. + int kappa; + bool result = DigitGen(scaled_boundary_minus, scaled_w, scaled_boundary_plus, + buffer, length, &kappa); + *decimal_exponent = -mk + kappa; + return result; +} + + +// The "counted" version of grisu3 (see above) only generates requested_digits +// number of digits. This version does not generate the shortest representation, +// and with enough requested digits 0.1 will at some point print as 0.9999999... +// Grisu3 is too imprecise for real halfway cases (1.5 will not work) and +// therefore the rounding strategy for halfway cases is irrelevant. +static bool Grisu3Counted(double v, + int requested_digits, + Vector buffer, + int* length, + int* decimal_exponent) { + DiyFp w = Double(v).AsNormalizedDiyFp(); + DiyFp ten_mk; // Cached power of ten: 10^-k + int mk; // -k + int ten_mk_minimal_binary_exponent = + kMinimalTargetExponent - (w.e() + DiyFp::kSignificandSize); + int ten_mk_maximal_binary_exponent = + kMaximalTargetExponent - (w.e() + DiyFp::kSignificandSize); + PowersOfTenCache::GetCachedPowerForBinaryExponentRange( + ten_mk_minimal_binary_exponent, + ten_mk_maximal_binary_exponent, + &ten_mk, &mk); + ASSERT((kMinimalTargetExponent <= w.e() + ten_mk.e() + + DiyFp::kSignificandSize) && + (kMaximalTargetExponent >= w.e() + ten_mk.e() + + DiyFp::kSignificandSize)); + // Note that ten_mk is only an approximation of 10^-k. A DiyFp only contains a + // 64 bit significand and ten_mk is thus only precise up to 64 bits. + + // The DiyFp::Times procedure rounds its result, and ten_mk is approximated + // too. The variable scaled_w (as well as scaled_boundary_minus/plus) are now + // off by a small amount. + // In fact: scaled_w - w*10^k < 1ulp (unit in the last place) of scaled_w. + // In other words: let f = scaled_w.f() and e = scaled_w.e(), then + // (f-1) * 2^e < w*10^k < (f+1) * 2^e + DiyFp scaled_w = DiyFp::Times(w, ten_mk); + + // We now have (double) (scaled_w * 10^-mk). + // DigitGen will generate the first requested_digits digits of scaled_w and + // return together with a kappa such that scaled_w ~= buffer * 10^kappa. (It + // will not always be exactly the same since DigitGenCounted only produces a + // limited number of digits.) + int kappa; + bool result = DigitGenCounted(scaled_w, requested_digits, + buffer, length, &kappa); + *decimal_exponent = -mk + kappa; + return result; +} + + +bool FastDtoa(double v, + FastDtoaMode mode, + int requested_digits, + Vector buffer, + int* length, + int* decimal_point) { + ASSERT(v > 0); + ASSERT(!Double(v).IsSpecial()); + + bool result = false; + int decimal_exponent = 0; + switch (mode) { + case FAST_DTOA_SHORTEST: + case FAST_DTOA_SHORTEST_SINGLE: + result = Grisu3(v, mode, buffer, length, &decimal_exponent); + break; + case FAST_DTOA_PRECISION: + result = Grisu3Counted(v, requested_digits, + buffer, length, &decimal_exponent); + break; + default: + UNREACHABLE(); + } + if (result) { + *decimal_point = *length + decimal_exponent; + buffer[*length] = '\0'; + } + return result; +} + +} // namespace double_conversion diff --git a/mfbt/double-conversion/fast-dtoa.h b/mfbt/double-conversion/fast-dtoa.h new file mode 100644 index 000000000000..5f1e8eee5e56 --- /dev/null +++ b/mfbt/double-conversion/fast-dtoa.h @@ -0,0 +1,88 @@ +// Copyright 2010 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef DOUBLE_CONVERSION_FAST_DTOA_H_ +#define DOUBLE_CONVERSION_FAST_DTOA_H_ + +#include "utils.h" + +namespace double_conversion { + +enum FastDtoaMode { + // Computes the shortest representation of the given input. The returned + // result will be the most accurate number of this length. Longer + // representations might be more accurate. + FAST_DTOA_SHORTEST, + // Same as FAST_DTOA_SHORTEST but for single-precision floats. + FAST_DTOA_SHORTEST_SINGLE, + // Computes a representation where the precision (number of digits) is + // given as input. The precision is independent of the decimal point. + FAST_DTOA_PRECISION +}; + +// FastDtoa will produce at most kFastDtoaMaximalLength digits. This does not +// include the terminating '\0' character. +static const int kFastDtoaMaximalLength = 17; +// Same for single-precision numbers. +static const int kFastDtoaMaximalSingleLength = 9; + +// Provides a decimal representation of v. +// The result should be interpreted as buffer * 10^(point - length). +// +// Precondition: +// * v must be a strictly positive finite double. +// +// Returns true if it succeeds, otherwise the result can not be trusted. +// There will be *length digits inside the buffer followed by a null terminator. +// If the function returns true and mode equals +// - FAST_DTOA_SHORTEST, then +// the parameter requested_digits is ignored. +// The result satisfies +// v == (double) (buffer * 10^(point - length)). +// The digits in the buffer are the shortest representation possible. E.g. +// if 0.099999999999 and 0.1 represent the same double then "1" is returned +// with point = 0. +// The last digit will be closest to the actual v. That is, even if several +// digits might correctly yield 'v' when read again, the buffer will contain +// the one closest to v. +// - FAST_DTOA_PRECISION, then +// the buffer contains requested_digits digits. +// the difference v - (buffer * 10^(point-length)) is closest to zero for +// all possible representations of requested_digits digits. +// If there are two values that are equally close, then FastDtoa returns +// false. +// For both modes the buffer must be large enough to hold the result. +bool FastDtoa(double d, + FastDtoaMode mode, + int requested_digits, + Vector buffer, + int* length, + int* decimal_point); + +} // namespace double_conversion + +#endif // DOUBLE_CONVERSION_FAST_DTOA_H_ diff --git a/mfbt/double-conversion/fixed-dtoa.cc b/mfbt/double-conversion/fixed-dtoa.cc new file mode 100644 index 000000000000..d56b1449b264 --- /dev/null +++ b/mfbt/double-conversion/fixed-dtoa.cc @@ -0,0 +1,402 @@ +// Copyright 2010 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include + +#include "fixed-dtoa.h" +#include "ieee.h" + +namespace double_conversion { + +// Represents a 128bit type. This class should be replaced by a native type on +// platforms that support 128bit integers. +class UInt128 { + public: + UInt128() : high_bits_(0), low_bits_(0) { } + UInt128(uint64_t high, uint64_t low) : high_bits_(high), low_bits_(low) { } + + void Multiply(uint32_t multiplicand) { + uint64_t accumulator; + + accumulator = (low_bits_ & kMask32) * multiplicand; + uint32_t part = static_cast(accumulator & kMask32); + accumulator >>= 32; + accumulator = accumulator + (low_bits_ >> 32) * multiplicand; + low_bits_ = (accumulator << 32) + part; + accumulator >>= 32; + accumulator = accumulator + (high_bits_ & kMask32) * multiplicand; + part = static_cast(accumulator & kMask32); + accumulator >>= 32; + accumulator = accumulator + (high_bits_ >> 32) * multiplicand; + high_bits_ = (accumulator << 32) + part; + ASSERT((accumulator >> 32) == 0); + } + + void Shift(int shift_amount) { + ASSERT(-64 <= shift_amount && shift_amount <= 64); + if (shift_amount == 0) { + return; + } else if (shift_amount == -64) { + high_bits_ = low_bits_; + low_bits_ = 0; + } else if (shift_amount == 64) { + low_bits_ = high_bits_; + high_bits_ = 0; + } else if (shift_amount <= 0) { + high_bits_ <<= -shift_amount; + high_bits_ += low_bits_ >> (64 + shift_amount); + low_bits_ <<= -shift_amount; + } else { + low_bits_ >>= shift_amount; + low_bits_ += high_bits_ << (64 - shift_amount); + high_bits_ >>= shift_amount; + } + } + + // Modifies *this to *this MOD (2^power). + // Returns *this DIV (2^power). + int DivModPowerOf2(int power) { + if (power >= 64) { + int result = static_cast(high_bits_ >> (power - 64)); + high_bits_ -= static_cast(result) << (power - 64); + return result; + } else { + uint64_t part_low = low_bits_ >> power; + uint64_t part_high = high_bits_ << (64 - power); + int result = static_cast(part_low + part_high); + high_bits_ = 0; + low_bits_ -= part_low << power; + return result; + } + } + + bool IsZero() const { + return high_bits_ == 0 && low_bits_ == 0; + } + + int BitAt(int position) { + if (position >= 64) { + return static_cast(high_bits_ >> (position - 64)) & 1; + } else { + return static_cast(low_bits_ >> position) & 1; + } + } + + private: + static const uint64_t kMask32 = 0xFFFFFFFF; + // Value == (high_bits_ << 64) + low_bits_ + uint64_t high_bits_; + uint64_t low_bits_; +}; + + +static const int kDoubleSignificandSize = 53; // Includes the hidden bit. + + +static void FillDigits32FixedLength(uint32_t number, int requested_length, + Vector buffer, int* length) { + for (int i = requested_length - 1; i >= 0; --i) { + buffer[(*length) + i] = '0' + number % 10; + number /= 10; + } + *length += requested_length; +} + + +static void FillDigits32(uint32_t number, Vector buffer, int* length) { + int number_length = 0; + // We fill the digits in reverse order and exchange them afterwards. + while (number != 0) { + int digit = number % 10; + number /= 10; + buffer[(*length) + number_length] = '0' + digit; + number_length++; + } + // Exchange the digits. + int i = *length; + int j = *length + number_length - 1; + while (i < j) { + char tmp = buffer[i]; + buffer[i] = buffer[j]; + buffer[j] = tmp; + i++; + j--; + } + *length += number_length; +} + + +static void FillDigits64FixedLength(uint64_t number, int requested_length, + Vector buffer, int* length) { + const uint32_t kTen7 = 10000000; + // For efficiency cut the number into 3 uint32_t parts, and print those. + uint32_t part2 = static_cast(number % kTen7); + number /= kTen7; + uint32_t part1 = static_cast(number % kTen7); + uint32_t part0 = static_cast(number / kTen7); + + FillDigits32FixedLength(part0, 3, buffer, length); + FillDigits32FixedLength(part1, 7, buffer, length); + FillDigits32FixedLength(part2, 7, buffer, length); +} + + +static void FillDigits64(uint64_t number, Vector buffer, int* length) { + const uint32_t kTen7 = 10000000; + // For efficiency cut the number into 3 uint32_t parts, and print those. + uint32_t part2 = static_cast(number % kTen7); + number /= kTen7; + uint32_t part1 = static_cast(number % kTen7); + uint32_t part0 = static_cast(number / kTen7); + + if (part0 != 0) { + FillDigits32(part0, buffer, length); + FillDigits32FixedLength(part1, 7, buffer, length); + FillDigits32FixedLength(part2, 7, buffer, length); + } else if (part1 != 0) { + FillDigits32(part1, buffer, length); + FillDigits32FixedLength(part2, 7, buffer, length); + } else { + FillDigits32(part2, buffer, length); + } +} + + +static void RoundUp(Vector buffer, int* length, int* decimal_point) { + // An empty buffer represents 0. + if (*length == 0) { + buffer[0] = '1'; + *decimal_point = 1; + *length = 1; + return; + } + // Round the last digit until we either have a digit that was not '9' or until + // we reached the first digit. + buffer[(*length) - 1]++; + for (int i = (*length) - 1; i > 0; --i) { + if (buffer[i] != '0' + 10) { + return; + } + buffer[i] = '0'; + buffer[i - 1]++; + } + // If the first digit is now '0' + 10, we would need to set it to '0' and add + // a '1' in front. However we reach the first digit only if all following + // digits had been '9' before rounding up. Now all trailing digits are '0' and + // we simply switch the first digit to '1' and update the decimal-point + // (indicating that the point is now one digit to the right). + if (buffer[0] == '0' + 10) { + buffer[0] = '1'; + (*decimal_point)++; + } +} + + +// The given fractionals number represents a fixed-point number with binary +// point at bit (-exponent). +// Preconditions: +// -128 <= exponent <= 0. +// 0 <= fractionals * 2^exponent < 1 +// The buffer holds the result. +// The function will round its result. During the rounding-process digits not +// generated by this function might be updated, and the decimal-point variable +// might be updated. If this function generates the digits 99 and the buffer +// already contained "199" (thus yielding a buffer of "19999") then a +// rounding-up will change the contents of the buffer to "20000". +static void FillFractionals(uint64_t fractionals, int exponent, + int fractional_count, Vector buffer, + int* length, int* decimal_point) { + ASSERT(-128 <= exponent && exponent <= 0); + // 'fractionals' is a fixed-point number, with binary point at bit + // (-exponent). Inside the function the non-converted remainder of fractionals + // is a fixed-point number, with binary point at bit 'point'. + if (-exponent <= 64) { + // One 64 bit number is sufficient. + ASSERT(fractionals >> 56 == 0); + int point = -exponent; + for (int i = 0; i < fractional_count; ++i) { + if (fractionals == 0) break; + // Instead of multiplying by 10 we multiply by 5 and adjust the point + // location. This way the fractionals variable will not overflow. + // Invariant at the beginning of the loop: fractionals < 2^point. + // Initially we have: point <= 64 and fractionals < 2^56 + // After each iteration the point is decremented by one. + // Note that 5^3 = 125 < 128 = 2^7. + // Therefore three iterations of this loop will not overflow fractionals + // (even without the subtraction at the end of the loop body). At this + // time point will satisfy point <= 61 and therefore fractionals < 2^point + // and any further multiplication of fractionals by 5 will not overflow. + fractionals *= 5; + point--; + int digit = static_cast(fractionals >> point); + buffer[*length] = '0' + digit; + (*length)++; + fractionals -= static_cast(digit) << point; + } + // If the first bit after the point is set we have to round up. + if (((fractionals >> (point - 1)) & 1) == 1) { + RoundUp(buffer, length, decimal_point); + } + } else { // We need 128 bits. + ASSERT(64 < -exponent && -exponent <= 128); + UInt128 fractionals128 = UInt128(fractionals, 0); + fractionals128.Shift(-exponent - 64); + int point = 128; + for (int i = 0; i < fractional_count; ++i) { + if (fractionals128.IsZero()) break; + // As before: instead of multiplying by 10 we multiply by 5 and adjust the + // point location. + // This multiplication will not overflow for the same reasons as before. + fractionals128.Multiply(5); + point--; + int digit = fractionals128.DivModPowerOf2(point); + buffer[*length] = '0' + digit; + (*length)++; + } + if (fractionals128.BitAt(point - 1) == 1) { + RoundUp(buffer, length, decimal_point); + } + } +} + + +// Removes leading and trailing zeros. +// If leading zeros are removed then the decimal point position is adjusted. +static void TrimZeros(Vector buffer, int* length, int* decimal_point) { + while (*length > 0 && buffer[(*length) - 1] == '0') { + (*length)--; + } + int first_non_zero = 0; + while (first_non_zero < *length && buffer[first_non_zero] == '0') { + first_non_zero++; + } + if (first_non_zero != 0) { + for (int i = first_non_zero; i < *length; ++i) { + buffer[i - first_non_zero] = buffer[i]; + } + *length -= first_non_zero; + *decimal_point -= first_non_zero; + } +} + + +bool FastFixedDtoa(double v, + int fractional_count, + Vector buffer, + int* length, + int* decimal_point) { + const uint32_t kMaxUInt32 = 0xFFFFFFFF; + uint64_t significand = Double(v).Significand(); + int exponent = Double(v).Exponent(); + // v = significand * 2^exponent (with significand a 53bit integer). + // If the exponent is larger than 20 (i.e. we may have a 73bit number) then we + // don't know how to compute the representation. 2^73 ~= 9.5*10^21. + // If necessary this limit could probably be increased, but we don't need + // more. + if (exponent > 20) return false; + if (fractional_count > 20) return false; + *length = 0; + // At most kDoubleSignificandSize bits of the significand are non-zero. + // Given a 64 bit integer we have 11 0s followed by 53 potentially non-zero + // bits: 0..11*..0xxx..53*..xx + if (exponent + kDoubleSignificandSize > 64) { + // The exponent must be > 11. + // + // We know that v = significand * 2^exponent. + // And the exponent > 11. + // We simplify the task by dividing v by 10^17. + // The quotient delivers the first digits, and the remainder fits into a 64 + // bit number. + // Dividing by 10^17 is equivalent to dividing by 5^17*2^17. + const uint64_t kFive17 = UINT64_2PART_C(0xB1, A2BC2EC5); // 5^17 + uint64_t divisor = kFive17; + int divisor_power = 17; + uint64_t dividend = significand; + uint32_t quotient; + uint64_t remainder; + // Let v = f * 2^e with f == significand and e == exponent. + // Then need q (quotient) and r (remainder) as follows: + // v = q * 10^17 + r + // f * 2^e = q * 10^17 + r + // f * 2^e = q * 5^17 * 2^17 + r + // If e > 17 then + // f * 2^(e-17) = q * 5^17 + r/2^17 + // else + // f = q * 5^17 * 2^(17-e) + r/2^e + if (exponent > divisor_power) { + // We only allow exponents of up to 20 and therefore (17 - e) <= 3 + dividend <<= exponent - divisor_power; + quotient = static_cast(dividend / divisor); + remainder = (dividend % divisor) << divisor_power; + } else { + divisor <<= divisor_power - exponent; + quotient = static_cast(dividend / divisor); + remainder = (dividend % divisor) << exponent; + } + FillDigits32(quotient, buffer, length); + FillDigits64FixedLength(remainder, divisor_power, buffer, length); + *decimal_point = *length; + } else if (exponent >= 0) { + // 0 <= exponent <= 11 + significand <<= exponent; + FillDigits64(significand, buffer, length); + *decimal_point = *length; + } else if (exponent > -kDoubleSignificandSize) { + // We have to cut the number. + uint64_t integrals = significand >> -exponent; + uint64_t fractionals = significand - (integrals << -exponent); + if (integrals > kMaxUInt32) { + FillDigits64(integrals, buffer, length); + } else { + FillDigits32(static_cast(integrals), buffer, length); + } + *decimal_point = *length; + FillFractionals(fractionals, exponent, fractional_count, + buffer, length, decimal_point); + } else if (exponent < -128) { + // This configuration (with at most 20 digits) means that all digits must be + // 0. + ASSERT(fractional_count <= 20); + buffer[0] = '\0'; + *length = 0; + *decimal_point = -fractional_count; + } else { + *decimal_point = 0; + FillFractionals(significand, exponent, fractional_count, + buffer, length, decimal_point); + } + TrimZeros(buffer, length, decimal_point); + buffer[*length] = '\0'; + if ((*length) == 0) { + // The string is empty and the decimal_point thus has no importance. Mimick + // Gay's dtoa and and set it to -fractional_count. + *decimal_point = -fractional_count; + } + return true; +} + +} // namespace double_conversion diff --git a/mfbt/double-conversion/fixed-dtoa.h b/mfbt/double-conversion/fixed-dtoa.h new file mode 100644 index 000000000000..3bdd08e21f59 --- /dev/null +++ b/mfbt/double-conversion/fixed-dtoa.h @@ -0,0 +1,56 @@ +// Copyright 2010 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef DOUBLE_CONVERSION_FIXED_DTOA_H_ +#define DOUBLE_CONVERSION_FIXED_DTOA_H_ + +#include "utils.h" + +namespace double_conversion { + +// Produces digits necessary to print a given number with +// 'fractional_count' digits after the decimal point. +// The buffer must be big enough to hold the result plus one terminating null +// character. +// +// The produced digits might be too short in which case the caller has to fill +// the gaps with '0's. +// Example: FastFixedDtoa(0.001, 5, ...) is allowed to return buffer = "1", and +// decimal_point = -2. +// Halfway cases are rounded towards +/-Infinity (away from 0). The call +// FastFixedDtoa(0.15, 2, ...) thus returns buffer = "2", decimal_point = 0. +// The returned buffer may contain digits that would be truncated from the +// shortest representation of the input. +// +// This method only works for some parameters. If it can't handle the input it +// returns false. The output is null-terminated when the function succeeds. +bool FastFixedDtoa(double v, int fractional_count, + Vector buffer, int* length, int* decimal_point); + +} // namespace double_conversion + +#endif // DOUBLE_CONVERSION_FIXED_DTOA_H_ diff --git a/mfbt/double-conversion/ieee.h b/mfbt/double-conversion/ieee.h new file mode 100644 index 000000000000..839dc47d455a --- /dev/null +++ b/mfbt/double-conversion/ieee.h @@ -0,0 +1,398 @@ +// Copyright 2012 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef DOUBLE_CONVERSION_DOUBLE_H_ +#define DOUBLE_CONVERSION_DOUBLE_H_ + +#include "diy-fp.h" + +namespace double_conversion { + +// We assume that doubles and uint64_t have the same endianness. +static uint64_t double_to_uint64(double d) { return BitCast(d); } +static double uint64_to_double(uint64_t d64) { return BitCast(d64); } +static uint32_t float_to_uint32(float f) { return BitCast(f); } +static float uint32_to_float(uint32_t d32) { return BitCast(d32); } + +// Helper functions for doubles. +class Double { + public: + static const uint64_t kSignMask = UINT64_2PART_C(0x80000000, 00000000); + static const uint64_t kExponentMask = UINT64_2PART_C(0x7FF00000, 00000000); + static const uint64_t kSignificandMask = UINT64_2PART_C(0x000FFFFF, FFFFFFFF); + static const uint64_t kHiddenBit = UINT64_2PART_C(0x00100000, 00000000); + static const int kPhysicalSignificandSize = 52; // Excludes the hidden bit. + static const int kSignificandSize = 53; + + Double() : d64_(0) {} + explicit Double(double d) : d64_(double_to_uint64(d)) {} + explicit Double(uint64_t d64) : d64_(d64) {} + explicit Double(DiyFp diy_fp) + : d64_(DiyFpToUint64(diy_fp)) {} + + // The value encoded by this Double must be greater or equal to +0.0. + // It must not be special (infinity, or NaN). + DiyFp AsDiyFp() const { + ASSERT(Sign() > 0); + ASSERT(!IsSpecial()); + return DiyFp(Significand(), Exponent()); + } + + // The value encoded by this Double must be strictly greater than 0. + DiyFp AsNormalizedDiyFp() const { + ASSERT(value() > 0.0); + uint64_t f = Significand(); + int e = Exponent(); + + // The current double could be a denormal. + while ((f & kHiddenBit) == 0) { + f <<= 1; + e--; + } + // Do the final shifts in one go. + f <<= DiyFp::kSignificandSize - kSignificandSize; + e -= DiyFp::kSignificandSize - kSignificandSize; + return DiyFp(f, e); + } + + // Returns the double's bit as uint64. + uint64_t AsUint64() const { + return d64_; + } + + // Returns the next greater double. Returns +infinity on input +infinity. + double NextDouble() const { + if (d64_ == kInfinity) return Double(kInfinity).value(); + if (Sign() < 0 && Significand() == 0) { + // -0.0 + return 0.0; + } + if (Sign() < 0) { + return Double(d64_ - 1).value(); + } else { + return Double(d64_ + 1).value(); + } + } + + double PreviousDouble() const { + if (d64_ == (kInfinity | kSignMask)) return -Double::Infinity(); + if (Sign() < 0) { + return Double(d64_ + 1).value(); + } else { + if (Significand() == 0) return -0.0; + return Double(d64_ - 1).value(); + } + } + + int Exponent() const { + if (IsDenormal()) return kDenormalExponent; + + uint64_t d64 = AsUint64(); + int biased_e = + static_cast((d64 & kExponentMask) >> kPhysicalSignificandSize); + return biased_e - kExponentBias; + } + + uint64_t Significand() const { + uint64_t d64 = AsUint64(); + uint64_t significand = d64 & kSignificandMask; + if (!IsDenormal()) { + return significand + kHiddenBit; + } else { + return significand; + } + } + + // Returns true if the double is a denormal. + bool IsDenormal() const { + uint64_t d64 = AsUint64(); + return (d64 & kExponentMask) == 0; + } + + // We consider denormals not to be special. + // Hence only Infinity and NaN are special. + bool IsSpecial() const { + uint64_t d64 = AsUint64(); + return (d64 & kExponentMask) == kExponentMask; + } + + bool IsNan() const { + uint64_t d64 = AsUint64(); + return ((d64 & kExponentMask) == kExponentMask) && + ((d64 & kSignificandMask) != 0); + } + + bool IsInfinite() const { + uint64_t d64 = AsUint64(); + return ((d64 & kExponentMask) == kExponentMask) && + ((d64 & kSignificandMask) == 0); + } + + int Sign() const { + uint64_t d64 = AsUint64(); + return (d64 & kSignMask) == 0? 1: -1; + } + + // Precondition: the value encoded by this Double must be greater or equal + // than +0.0. + DiyFp UpperBoundary() const { + ASSERT(Sign() > 0); + return DiyFp(Significand() * 2 + 1, Exponent() - 1); + } + + // Computes the two boundaries of this. + // The bigger boundary (m_plus) is normalized. The lower boundary has the same + // exponent as m_plus. + // Precondition: the value encoded by this Double must be greater than 0. + void NormalizedBoundaries(DiyFp* out_m_minus, DiyFp* out_m_plus) const { + ASSERT(value() > 0.0); + DiyFp v = this->AsDiyFp(); + DiyFp m_plus = DiyFp::Normalize(DiyFp((v.f() << 1) + 1, v.e() - 1)); + DiyFp m_minus; + if (LowerBoundaryIsCloser()) { + m_minus = DiyFp((v.f() << 2) - 1, v.e() - 2); + } else { + m_minus = DiyFp((v.f() << 1) - 1, v.e() - 1); + } + m_minus.set_f(m_minus.f() << (m_minus.e() - m_plus.e())); + m_minus.set_e(m_plus.e()); + *out_m_plus = m_plus; + *out_m_minus = m_minus; + } + + bool LowerBoundaryIsCloser() const { + // The boundary is closer if the significand is of the form f == 2^p-1 then + // the lower boundary is closer. + // Think of v = 1000e10 and v- = 9999e9. + // Then the boundary (== (v - v-)/2) is not just at a distance of 1e9 but + // at a distance of 1e8. + // The only exception is for the smallest normal: the largest denormal is + // at the same distance as its successor. + // Note: denormals have the same exponent as the smallest normals. + bool physical_significand_is_zero = ((AsUint64() & kSignificandMask) == 0); + return physical_significand_is_zero && (Exponent() != kDenormalExponent); + } + + double value() const { return uint64_to_double(d64_); } + + // Returns the significand size for a given order of magnitude. + // If v = f*2^e with 2^p-1 <= f <= 2^p then p+e is v's order of magnitude. + // This function returns the number of significant binary digits v will have + // once it's encoded into a double. In almost all cases this is equal to + // kSignificandSize. The only exceptions are denormals. They start with + // leading zeroes and their effective significand-size is hence smaller. + static int SignificandSizeForOrderOfMagnitude(int order) { + if (order >= (kDenormalExponent + kSignificandSize)) { + return kSignificandSize; + } + if (order <= kDenormalExponent) return 0; + return order - kDenormalExponent; + } + + static double Infinity() { + return Double(kInfinity).value(); + } + + static double NaN() { + return Double(kNaN).value(); + } + + private: + static const int kExponentBias = 0x3FF + kPhysicalSignificandSize; + static const int kDenormalExponent = -kExponentBias + 1; + static const int kMaxExponent = 0x7FF - kExponentBias; + static const uint64_t kInfinity = UINT64_2PART_C(0x7FF00000, 00000000); + static const uint64_t kNaN = UINT64_2PART_C(0x7FF80000, 00000000); + + const uint64_t d64_; + + static uint64_t DiyFpToUint64(DiyFp diy_fp) { + uint64_t significand = diy_fp.f(); + int exponent = diy_fp.e(); + while (significand > kHiddenBit + kSignificandMask) { + significand >>= 1; + exponent++; + } + if (exponent >= kMaxExponent) { + return kInfinity; + } + if (exponent < kDenormalExponent) { + return 0; + } + while (exponent > kDenormalExponent && (significand & kHiddenBit) == 0) { + significand <<= 1; + exponent--; + } + uint64_t biased_exponent; + if (exponent == kDenormalExponent && (significand & kHiddenBit) == 0) { + biased_exponent = 0; + } else { + biased_exponent = static_cast(exponent + kExponentBias); + } + return (significand & kSignificandMask) | + (biased_exponent << kPhysicalSignificandSize); + } +}; + +class Single { + public: + static const uint32_t kSignMask = 0x80000000; + static const uint32_t kExponentMask = 0x7F800000; + static const uint32_t kSignificandMask = 0x007FFFFF; + static const uint32_t kHiddenBit = 0x00800000; + static const int kPhysicalSignificandSize = 23; // Excludes the hidden bit. + static const int kSignificandSize = 24; + + Single() : d32_(0) {} + explicit Single(float f) : d32_(float_to_uint32(f)) {} + explicit Single(uint32_t d32) : d32_(d32) {} + + // The value encoded by this Single must be greater or equal to +0.0. + // It must not be special (infinity, or NaN). + DiyFp AsDiyFp() const { + ASSERT(Sign() > 0); + ASSERT(!IsSpecial()); + return DiyFp(Significand(), Exponent()); + } + + // Returns the single's bit as uint64. + uint32_t AsUint32() const { + return d32_; + } + + int Exponent() const { + if (IsDenormal()) return kDenormalExponent; + + uint32_t d32 = AsUint32(); + int biased_e = + static_cast((d32 & kExponentMask) >> kPhysicalSignificandSize); + return biased_e - kExponentBias; + } + + uint32_t Significand() const { + uint32_t d32 = AsUint32(); + uint32_t significand = d32 & kSignificandMask; + if (!IsDenormal()) { + return significand + kHiddenBit; + } else { + return significand; + } + } + + // Returns true if the single is a denormal. + bool IsDenormal() const { + uint32_t d32 = AsUint32(); + return (d32 & kExponentMask) == 0; + } + + // We consider denormals not to be special. + // Hence only Infinity and NaN are special. + bool IsSpecial() const { + uint32_t d32 = AsUint32(); + return (d32 & kExponentMask) == kExponentMask; + } + + bool IsNan() const { + uint32_t d32 = AsUint32(); + return ((d32 & kExponentMask) == kExponentMask) && + ((d32 & kSignificandMask) != 0); + } + + bool IsInfinite() const { + uint32_t d32 = AsUint32(); + return ((d32 & kExponentMask) == kExponentMask) && + ((d32 & kSignificandMask) == 0); + } + + int Sign() const { + uint32_t d32 = AsUint32(); + return (d32 & kSignMask) == 0? 1: -1; + } + + // Computes the two boundaries of this. + // The bigger boundary (m_plus) is normalized. The lower boundary has the same + // exponent as m_plus. + // Precondition: the value encoded by this Single must be greater than 0. + void NormalizedBoundaries(DiyFp* out_m_minus, DiyFp* out_m_plus) const { + ASSERT(value() > 0.0); + DiyFp v = this->AsDiyFp(); + DiyFp m_plus = DiyFp::Normalize(DiyFp((v.f() << 1) + 1, v.e() - 1)); + DiyFp m_minus; + if (LowerBoundaryIsCloser()) { + m_minus = DiyFp((v.f() << 2) - 1, v.e() - 2); + } else { + m_minus = DiyFp((v.f() << 1) - 1, v.e() - 1); + } + m_minus.set_f(m_minus.f() << (m_minus.e() - m_plus.e())); + m_minus.set_e(m_plus.e()); + *out_m_plus = m_plus; + *out_m_minus = m_minus; + } + + // Precondition: the value encoded by this Single must be greater or equal + // than +0.0. + DiyFp UpperBoundary() const { + ASSERT(Sign() > 0); + return DiyFp(Significand() * 2 + 1, Exponent() - 1); + } + + bool LowerBoundaryIsCloser() const { + // The boundary is closer if the significand is of the form f == 2^p-1 then + // the lower boundary is closer. + // Think of v = 1000e10 and v- = 9999e9. + // Then the boundary (== (v - v-)/2) is not just at a distance of 1e9 but + // at a distance of 1e8. + // The only exception is for the smallest normal: the largest denormal is + // at the same distance as its successor. + // Note: denormals have the same exponent as the smallest normals. + bool physical_significand_is_zero = ((AsUint32() & kSignificandMask) == 0); + return physical_significand_is_zero && (Exponent() != kDenormalExponent); + } + + float value() const { return uint32_to_float(d32_); } + + static float Infinity() { + return Single(kInfinity).value(); + } + + static float NaN() { + return Single(kNaN).value(); + } + + private: + static const int kExponentBias = 0x7F + kPhysicalSignificandSize; + static const int kDenormalExponent = -kExponentBias + 1; + static const int kMaxExponent = 0xFF - kExponentBias; + static const uint32_t kInfinity = 0x7F800000; + static const uint32_t kNaN = 0x7FC00000; + + const uint32_t d32_; +}; + +} // namespace double_conversion + +#endif // DOUBLE_CONVERSION_DOUBLE_H_ diff --git a/mfbt/double-conversion/strtod.cc b/mfbt/double-conversion/strtod.cc new file mode 100644 index 000000000000..d5abc937c9df --- /dev/null +++ b/mfbt/double-conversion/strtod.cc @@ -0,0 +1,554 @@ +// Copyright 2010 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include +#include + +#include "strtod.h" +#include "bignum.h" +#include "cached-powers.h" +#include "ieee.h" + +namespace double_conversion { + +// 2^53 = 9007199254740992. +// Any integer with at most 15 decimal digits will hence fit into a double +// (which has a 53bit significand) without loss of precision. +static const int kMaxExactDoubleIntegerDecimalDigits = 15; +// 2^64 = 18446744073709551616 > 10^19 +static const int kMaxUint64DecimalDigits = 19; + +// Max double: 1.7976931348623157 x 10^308 +// Min non-zero double: 4.9406564584124654 x 10^-324 +// Any x >= 10^309 is interpreted as +infinity. +// Any x <= 10^-324 is interpreted as 0. +// Note that 2.5e-324 (despite being smaller than the min double) will be read +// as non-zero (equal to the min non-zero double). +static const int kMaxDecimalPower = 309; +static const int kMinDecimalPower = -324; + +// 2^64 = 18446744073709551616 +static const uint64_t kMaxUint64 = UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF); + + +static const double exact_powers_of_ten[] = { + 1.0, // 10^0 + 10.0, + 100.0, + 1000.0, + 10000.0, + 100000.0, + 1000000.0, + 10000000.0, + 100000000.0, + 1000000000.0, + 10000000000.0, // 10^10 + 100000000000.0, + 1000000000000.0, + 10000000000000.0, + 100000000000000.0, + 1000000000000000.0, + 10000000000000000.0, + 100000000000000000.0, + 1000000000000000000.0, + 10000000000000000000.0, + 100000000000000000000.0, // 10^20 + 1000000000000000000000.0, + // 10^22 = 0x21e19e0c9bab2400000 = 0x878678326eac9 * 2^22 + 10000000000000000000000.0 +}; +static const int kExactPowersOfTenSize = ARRAY_SIZE(exact_powers_of_ten); + +// Maximum number of significant digits in the decimal representation. +// In fact the value is 772 (see conversions.cc), but to give us some margin +// we round up to 780. +static const int kMaxSignificantDecimalDigits = 780; + +static Vector TrimLeadingZeros(Vector buffer) { + for (int i = 0; i < buffer.length(); i++) { + if (buffer[i] != '0') { + return buffer.SubVector(i, buffer.length()); + } + } + return Vector(buffer.start(), 0); +} + + +static Vector TrimTrailingZeros(Vector buffer) { + for (int i = buffer.length() - 1; i >= 0; --i) { + if (buffer[i] != '0') { + return buffer.SubVector(0, i + 1); + } + } + return Vector(buffer.start(), 0); +} + + +static void CutToMaxSignificantDigits(Vector buffer, + int exponent, + char* significant_buffer, + int* significant_exponent) { + for (int i = 0; i < kMaxSignificantDecimalDigits - 1; ++i) { + significant_buffer[i] = buffer[i]; + } + // The input buffer has been trimmed. Therefore the last digit must be + // different from '0'. + ASSERT(buffer[buffer.length() - 1] != '0'); + // Set the last digit to be non-zero. This is sufficient to guarantee + // correct rounding. + significant_buffer[kMaxSignificantDecimalDigits - 1] = '1'; + *significant_exponent = + exponent + (buffer.length() - kMaxSignificantDecimalDigits); +} + + +// Trims the buffer and cuts it to at most kMaxSignificantDecimalDigits. +// If possible the input-buffer is reused, but if the buffer needs to be +// modified (due to cutting), then the input needs to be copied into the +// buffer_copy_space. +static void TrimAndCut(Vector buffer, int exponent, + char* buffer_copy_space, int space_size, + Vector* trimmed, int* updated_exponent) { + Vector left_trimmed = TrimLeadingZeros(buffer); + Vector right_trimmed = TrimTrailingZeros(left_trimmed); + exponent += left_trimmed.length() - right_trimmed.length(); + if (right_trimmed.length() > kMaxSignificantDecimalDigits) { + ASSERT(space_size >= kMaxSignificantDecimalDigits); + CutToMaxSignificantDigits(right_trimmed, exponent, + buffer_copy_space, updated_exponent); + *trimmed = Vector(buffer_copy_space, + kMaxSignificantDecimalDigits); + } else { + *trimmed = right_trimmed; + *updated_exponent = exponent; + } +} + + +// Reads digits from the buffer and converts them to a uint64. +// Reads in as many digits as fit into a uint64. +// When the string starts with "1844674407370955161" no further digit is read. +// Since 2^64 = 18446744073709551616 it would still be possible read another +// digit if it was less or equal than 6, but this would complicate the code. +static uint64_t ReadUint64(Vector buffer, + int* number_of_read_digits) { + uint64_t result = 0; + int i = 0; + while (i < buffer.length() && result <= (kMaxUint64 / 10 - 1)) { + int digit = buffer[i++] - '0'; + ASSERT(0 <= digit && digit <= 9); + result = 10 * result + digit; + } + *number_of_read_digits = i; + return result; +} + + +// Reads a DiyFp from the buffer. +// The returned DiyFp is not necessarily normalized. +// If remaining_decimals is zero then the returned DiyFp is accurate. +// Otherwise it has been rounded and has error of at most 1/2 ulp. +static void ReadDiyFp(Vector buffer, + DiyFp* result, + int* remaining_decimals) { + int read_digits; + uint64_t significand = ReadUint64(buffer, &read_digits); + if (buffer.length() == read_digits) { + *result = DiyFp(significand, 0); + *remaining_decimals = 0; + } else { + // Round the significand. + if (buffer[read_digits] >= '5') { + significand++; + } + // Compute the binary exponent. + int exponent = 0; + *result = DiyFp(significand, exponent); + *remaining_decimals = buffer.length() - read_digits; + } +} + + +static bool DoubleStrtod(Vector trimmed, + int exponent, + double* result) { +#if !defined(DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS) + // On x86 the floating-point stack can be 64 or 80 bits wide. If it is + // 80 bits wide (as is the case on Linux) then double-rounding occurs and the + // result is not accurate. + // We know that Windows32 uses 64 bits and is therefore accurate. + // Note that the ARM simulator is compiled for 32bits. It therefore exhibits + // the same problem. + return false; +#endif + if (trimmed.length() <= kMaxExactDoubleIntegerDecimalDigits) { + int read_digits; + // The trimmed input fits into a double. + // If the 10^exponent (resp. 10^-exponent) fits into a double too then we + // can compute the result-double simply by multiplying (resp. dividing) the + // two numbers. + // This is possible because IEEE guarantees that floating-point operations + // return the best possible approximation. + if (exponent < 0 && -exponent < kExactPowersOfTenSize) { + // 10^-exponent fits into a double. + *result = static_cast(ReadUint64(trimmed, &read_digits)); + ASSERT(read_digits == trimmed.length()); + *result /= exact_powers_of_ten[-exponent]; + return true; + } + if (0 <= exponent && exponent < kExactPowersOfTenSize) { + // 10^exponent fits into a double. + *result = static_cast(ReadUint64(trimmed, &read_digits)); + ASSERT(read_digits == trimmed.length()); + *result *= exact_powers_of_ten[exponent]; + return true; + } + int remaining_digits = + kMaxExactDoubleIntegerDecimalDigits - trimmed.length(); + if ((0 <= exponent) && + (exponent - remaining_digits < kExactPowersOfTenSize)) { + // The trimmed string was short and we can multiply it with + // 10^remaining_digits. As a result the remaining exponent now fits + // into a double too. + *result = static_cast(ReadUint64(trimmed, &read_digits)); + ASSERT(read_digits == trimmed.length()); + *result *= exact_powers_of_ten[remaining_digits]; + *result *= exact_powers_of_ten[exponent - remaining_digits]; + return true; + } + } + return false; +} + + +// Returns 10^exponent as an exact DiyFp. +// The given exponent must be in the range [1; kDecimalExponentDistance[. +static DiyFp AdjustmentPowerOfTen(int exponent) { + ASSERT(0 < exponent); + ASSERT(exponent < PowersOfTenCache::kDecimalExponentDistance); + // Simply hardcode the remaining powers for the given decimal exponent + // distance. + ASSERT(PowersOfTenCache::kDecimalExponentDistance == 8); + switch (exponent) { + case 1: return DiyFp(UINT64_2PART_C(0xa0000000, 00000000), -60); + case 2: return DiyFp(UINT64_2PART_C(0xc8000000, 00000000), -57); + case 3: return DiyFp(UINT64_2PART_C(0xfa000000, 00000000), -54); + case 4: return DiyFp(UINT64_2PART_C(0x9c400000, 00000000), -50); + case 5: return DiyFp(UINT64_2PART_C(0xc3500000, 00000000), -47); + case 6: return DiyFp(UINT64_2PART_C(0xf4240000, 00000000), -44); + case 7: return DiyFp(UINT64_2PART_C(0x98968000, 00000000), -40); + default: + UNREACHABLE(); + return DiyFp(0, 0); + } +} + + +// If the function returns true then the result is the correct double. +// Otherwise it is either the correct double or the double that is just below +// the correct double. +static bool DiyFpStrtod(Vector buffer, + int exponent, + double* result) { + DiyFp input; + int remaining_decimals; + ReadDiyFp(buffer, &input, &remaining_decimals); + // Since we may have dropped some digits the input is not accurate. + // If remaining_decimals is different than 0 than the error is at most + // .5 ulp (unit in the last place). + // We don't want to deal with fractions and therefore keep a common + // denominator. + const int kDenominatorLog = 3; + const int kDenominator = 1 << kDenominatorLog; + // Move the remaining decimals into the exponent. + exponent += remaining_decimals; + int error = (remaining_decimals == 0 ? 0 : kDenominator / 2); + + int old_e = input.e(); + input.Normalize(); + error <<= old_e - input.e(); + + ASSERT(exponent <= PowersOfTenCache::kMaxDecimalExponent); + if (exponent < PowersOfTenCache::kMinDecimalExponent) { + *result = 0.0; + return true; + } + DiyFp cached_power; + int cached_decimal_exponent; + PowersOfTenCache::GetCachedPowerForDecimalExponent(exponent, + &cached_power, + &cached_decimal_exponent); + + if (cached_decimal_exponent != exponent) { + int adjustment_exponent = exponent - cached_decimal_exponent; + DiyFp adjustment_power = AdjustmentPowerOfTen(adjustment_exponent); + input.Multiply(adjustment_power); + if (kMaxUint64DecimalDigits - buffer.length() >= adjustment_exponent) { + // The product of input with the adjustment power fits into a 64 bit + // integer. + ASSERT(DiyFp::kSignificandSize == 64); + } else { + // The adjustment power is exact. There is hence only an error of 0.5. + error += kDenominator / 2; + } + } + + input.Multiply(cached_power); + // The error introduced by a multiplication of a*b equals + // error_a + error_b + error_a*error_b/2^64 + 0.5 + // Substituting a with 'input' and b with 'cached_power' we have + // error_b = 0.5 (all cached powers have an error of less than 0.5 ulp), + // error_ab = 0 or 1 / kDenominator > error_a*error_b/ 2^64 + int error_b = kDenominator / 2; + int error_ab = (error == 0 ? 0 : 1); // We round up to 1. + int fixed_error = kDenominator / 2; + error += error_b + error_ab + fixed_error; + + old_e = input.e(); + input.Normalize(); + error <<= old_e - input.e(); + + // See if the double's significand changes if we add/subtract the error. + int order_of_magnitude = DiyFp::kSignificandSize + input.e(); + int effective_significand_size = + Double::SignificandSizeForOrderOfMagnitude(order_of_magnitude); + int precision_digits_count = + DiyFp::kSignificandSize - effective_significand_size; + if (precision_digits_count + kDenominatorLog >= DiyFp::kSignificandSize) { + // This can only happen for very small denormals. In this case the + // half-way multiplied by the denominator exceeds the range of an uint64. + // Simply shift everything to the right. + int shift_amount = (precision_digits_count + kDenominatorLog) - + DiyFp::kSignificandSize + 1; + input.set_f(input.f() >> shift_amount); + input.set_e(input.e() + shift_amount); + // We add 1 for the lost precision of error, and kDenominator for + // the lost precision of input.f(). + error = (error >> shift_amount) + 1 + kDenominator; + precision_digits_count -= shift_amount; + } + // We use uint64_ts now. This only works if the DiyFp uses uint64_ts too. + ASSERT(DiyFp::kSignificandSize == 64); + ASSERT(precision_digits_count < 64); + uint64_t one64 = 1; + uint64_t precision_bits_mask = (one64 << precision_digits_count) - 1; + uint64_t precision_bits = input.f() & precision_bits_mask; + uint64_t half_way = one64 << (precision_digits_count - 1); + precision_bits *= kDenominator; + half_way *= kDenominator; + DiyFp rounded_input(input.f() >> precision_digits_count, + input.e() + precision_digits_count); + if (precision_bits >= half_way + error) { + rounded_input.set_f(rounded_input.f() + 1); + } + // If the last_bits are too close to the half-way case than we are too + // inaccurate and round down. In this case we return false so that we can + // fall back to a more precise algorithm. + + *result = Double(rounded_input).value(); + if (half_way - error < precision_bits && precision_bits < half_way + error) { + // Too imprecise. The caller will have to fall back to a slower version. + // However the returned number is guaranteed to be either the correct + // double, or the next-lower double. + return false; + } else { + return true; + } +} + + +// Returns +// - -1 if buffer*10^exponent < diy_fp. +// - 0 if buffer*10^exponent == diy_fp. +// - +1 if buffer*10^exponent > diy_fp. +// Preconditions: +// buffer.length() + exponent <= kMaxDecimalPower + 1 +// buffer.length() + exponent > kMinDecimalPower +// buffer.length() <= kMaxDecimalSignificantDigits +static int CompareBufferWithDiyFp(Vector buffer, + int exponent, + DiyFp diy_fp) { + ASSERT(buffer.length() + exponent <= kMaxDecimalPower + 1); + ASSERT(buffer.length() + exponent > kMinDecimalPower); + ASSERT(buffer.length() <= kMaxSignificantDecimalDigits); + // Make sure that the Bignum will be able to hold all our numbers. + // Our Bignum implementation has a separate field for exponents. Shifts will + // consume at most one bigit (< 64 bits). + // ln(10) == 3.3219... + ASSERT(((kMaxDecimalPower + 1) * 333 / 100) < Bignum::kMaxSignificantBits); + Bignum buffer_bignum; + Bignum diy_fp_bignum; + buffer_bignum.AssignDecimalString(buffer); + diy_fp_bignum.AssignUInt64(diy_fp.f()); + if (exponent >= 0) { + buffer_bignum.MultiplyByPowerOfTen(exponent); + } else { + diy_fp_bignum.MultiplyByPowerOfTen(-exponent); + } + if (diy_fp.e() > 0) { + diy_fp_bignum.ShiftLeft(diy_fp.e()); + } else { + buffer_bignum.ShiftLeft(-diy_fp.e()); + } + return Bignum::Compare(buffer_bignum, diy_fp_bignum); +} + + +// Returns true if the guess is the correct double. +// Returns false, when guess is either correct or the next-lower double. +static bool ComputeGuess(Vector trimmed, int exponent, + double* guess) { + if (trimmed.length() == 0) { + *guess = 0.0; + return true; + } + if (exponent + trimmed.length() - 1 >= kMaxDecimalPower) { + *guess = Double::Infinity(); + return true; + } + if (exponent + trimmed.length() <= kMinDecimalPower) { + *guess = 0.0; + return true; + } + + if (DoubleStrtod(trimmed, exponent, guess) || + DiyFpStrtod(trimmed, exponent, guess)) { + return true; + } + if (*guess == Double::Infinity()) { + return true; + } + return false; +} + +double Strtod(Vector buffer, int exponent) { + char copy_buffer[kMaxSignificantDecimalDigits]; + Vector trimmed; + int updated_exponent; + TrimAndCut(buffer, exponent, copy_buffer, kMaxSignificantDecimalDigits, + &trimmed, &updated_exponent); + exponent = updated_exponent; + + double guess; + bool is_correct = ComputeGuess(trimmed, exponent, &guess); + if (is_correct) return guess; + + DiyFp upper_boundary = Double(guess).UpperBoundary(); + int comparison = CompareBufferWithDiyFp(trimmed, exponent, upper_boundary); + if (comparison < 0) { + return guess; + } else if (comparison > 0) { + return Double(guess).NextDouble(); + } else if ((Double(guess).Significand() & 1) == 0) { + // Round towards even. + return guess; + } else { + return Double(guess).NextDouble(); + } +} + +float Strtof(Vector buffer, int exponent) { + char copy_buffer[kMaxSignificantDecimalDigits]; + Vector trimmed; + int updated_exponent; + TrimAndCut(buffer, exponent, copy_buffer, kMaxSignificantDecimalDigits, + &trimmed, &updated_exponent); + exponent = updated_exponent; + + double double_guess; + bool is_correct = ComputeGuess(trimmed, exponent, &double_guess); + + float float_guess = static_cast(double_guess); + if (float_guess == double_guess) { + // This shortcut triggers for integer values. + return float_guess; + } + + // We must catch double-rounding. Say the double has been rounded up, and is + // now a boundary of a float, and rounds up again. This is why we have to + // look at previous too. + // Example (in decimal numbers): + // input: 12349 + // high-precision (4 digits): 1235 + // low-precision (3 digits): + // when read from input: 123 + // when rounded from high precision: 124. + // To do this we simply look at the neigbors of the correct result and see + // if they would round to the same float. If the guess is not correct we have + // to look at four values (since two different doubles could be the correct + // double). + + double double_next = Double(double_guess).NextDouble(); + double double_previous = Double(double_guess).PreviousDouble(); + + float f1 = static_cast(double_previous); + float f2 = float_guess; + float f3 = static_cast(double_next); + float f4; + if (is_correct) { + f4 = f3; + } else { + double double_next2 = Double(double_next).NextDouble(); + f4 = static_cast(double_next2); + } + assert(f1 <= f2 && f2 <= f3 && f3 <= f4); + + // If the guess doesn't lie near a single-precision boundary we can simply + // return its float-value. + if ((f1 == f4)) { + return float_guess; + } + + assert((f1 != f2 && f2 == f3 && f3 == f4) || + (f1 == f2 && f2 != f3 && f3 == f4) || + (f1 == f2 && f2 == f3 && f3 != f4)); + + // guess and next are the two possible canditates (in the same way that + // double_guess was the lower candidate for a double-precision guess). + float guess = f1; + float next = f4; + DiyFp upper_boundary; + if (guess == 0.0f) { + float min_float = 1e-45f; + upper_boundary = Double(static_cast(min_float) / 2).AsDiyFp(); + } else { + upper_boundary = Single(guess).UpperBoundary(); + } + int comparison = CompareBufferWithDiyFp(trimmed, exponent, upper_boundary); + if (comparison < 0) { + return guess; + } else if (comparison > 0) { + return next; + } else if ((Single(guess).Significand() & 1) == 0) { + // Round towards even. + return guess; + } else { + return next; + } +} + +} // namespace double_conversion diff --git a/mfbt/double-conversion/strtod.h b/mfbt/double-conversion/strtod.h new file mode 100644 index 000000000000..ed0293b8f54a --- /dev/null +++ b/mfbt/double-conversion/strtod.h @@ -0,0 +1,45 @@ +// Copyright 2010 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef DOUBLE_CONVERSION_STRTOD_H_ +#define DOUBLE_CONVERSION_STRTOD_H_ + +#include "utils.h" + +namespace double_conversion { + +// The buffer must only contain digits in the range [0-9]. It must not +// contain a dot or a sign. It must not start with '0', and must not be empty. +double Strtod(Vector buffer, int exponent); + +// The buffer must only contain digits in the range [0-9]. It must not +// contain a dot or a sign. It must not start with '0', and must not be empty. +float Strtof(Vector buffer, int exponent); + +} // namespace double_conversion + +#endif // DOUBLE_CONVERSION_STRTOD_H_ diff --git a/mfbt/double-conversion/utils.h b/mfbt/double-conversion/utils.h new file mode 100644 index 000000000000..bdc7d4bc0bda --- /dev/null +++ b/mfbt/double-conversion/utils.h @@ -0,0 +1,293 @@ +// Copyright 2010 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef DOUBLE_CONVERSION_UTILS_H_ +#define DOUBLE_CONVERSION_UTILS_H_ + +#include +#include + +#include +#ifndef ASSERT +#define ASSERT(condition) (assert(condition)) +#endif +#ifndef UNIMPLEMENTED +#define UNIMPLEMENTED() (abort()) +#endif +#ifndef UNREACHABLE +#define UNREACHABLE() (abort()) +#endif + +// Double operations detection based on target architecture. +// Linux uses a 80bit wide floating point stack on x86. This induces double +// rounding, which in turn leads to wrong results. +// An easy way to test if the floating-point operations are correct is to +// evaluate: 89255.0/1e22. If the floating-point stack is 64 bits wide then +// the result is equal to 89255e-22. +// The best way to test this, is to create a division-function and to compare +// the output of the division with the expected result. (Inlining must be +// disabled.) +// On Linux,x86 89255e-22 != Div_double(89255.0/1e22) +#if defined(_M_X64) || defined(__x86_64__) || \ + defined(__ARMEL__) || \ + defined(_MIPS_ARCH_MIPS32R2) +#define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1 +#elif defined(_M_IX86) || defined(__i386__) +#if defined(_WIN32) +// Windows uses a 64bit wide floating point stack. +#define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1 +#else +#undef DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS +#endif // _WIN32 +#else +#error Target architecture was not detected as supported by Double-Conversion. +#endif + + +#include "mozilla/StandardInteger.h" + +// The following macro works on both 32 and 64-bit platforms. +// Usage: instead of writing 0x1234567890123456 +// write UINT64_2PART_C(0x12345678,90123456); +#define UINT64_2PART_C(a, b) (((static_cast(a) << 32) + 0x##b##u)) + + +// The expression ARRAY_SIZE(a) is a compile-time constant of type +// size_t which represents the number of elements of the given +// array. You should only use ARRAY_SIZE on statically allocated +// arrays. +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(a) \ + ((sizeof(a) / sizeof(*(a))) / \ + static_cast(!(sizeof(a) % sizeof(*(a))))) +#endif + +// A macro to disallow the evil copy constructor and operator= functions +// This should be used in the private: declarations for a class +#ifndef DISALLOW_COPY_AND_ASSIGN +#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ + TypeName(const TypeName&); \ + void operator=(const TypeName&) +#endif + +// A macro to disallow all the implicit constructors, namely the +// default constructor, copy constructor and operator= functions. +// +// This should be used in the private: declarations for a class +// that wants to prevent anyone from instantiating it. This is +// especially useful for classes containing only static methods. +#ifndef DISALLOW_IMPLICIT_CONSTRUCTORS +#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ + TypeName(); \ + DISALLOW_COPY_AND_ASSIGN(TypeName) +#endif + +namespace double_conversion { + +static const int kCharSize = sizeof(char); + +// Returns the maximum of the two parameters. +template +static T Max(T a, T b) { + return a < b ? b : a; +} + + +// Returns the minimum of the two parameters. +template +static T Min(T a, T b) { + return a < b ? a : b; +} + + +inline int StrLength(const char* string) { + size_t length = strlen(string); + ASSERT(length == static_cast(static_cast(length))); + return static_cast(length); +} + +// This is a simplified version of V8's Vector class. +template +class Vector { + public: + Vector() : start_(NULL), length_(0) {} + Vector(T* data, int length) : start_(data), length_(length) { + ASSERT(length == 0 || (length > 0 && data != NULL)); + } + + // Returns a vector using the same backing storage as this one, + // spanning from and including 'from', to but not including 'to'. + Vector SubVector(int from, int to) { + ASSERT(to <= length_); + ASSERT(from < to); + ASSERT(0 <= from); + return Vector(start() + from, to - from); + } + + // Returns the length of the vector. + int length() const { return length_; } + + // Returns whether or not the vector is empty. + bool is_empty() const { return length_ == 0; } + + // Returns the pointer to the start of the data in the vector. + T* start() const { return start_; } + + // Access individual vector elements - checks bounds in debug mode. + T& operator[](int index) const { + ASSERT(0 <= index && index < length_); + return start_[index]; + } + + T& first() { return start_[0]; } + + T& last() { return start_[length_ - 1]; } + + private: + T* start_; + int length_; +}; + + +// Helper class for building result strings in a character buffer. The +// purpose of the class is to use safe operations that checks the +// buffer bounds on all operations in debug mode. +class StringBuilder { + public: + StringBuilder(char* buffer, int size) + : buffer_(buffer, size), position_(0) { } + + ~StringBuilder() { if (!is_finalized()) Finalize(); } + + int size() const { return buffer_.length(); } + + // Get the current position in the builder. + int position() const { + ASSERT(!is_finalized()); + return position_; + } + + // Reset the position. + void Reset() { position_ = 0; } + + // Add a single character to the builder. It is not allowed to add + // 0-characters; use the Finalize() method to terminate the string + // instead. + void AddCharacter(char c) { + ASSERT(c != '\0'); + ASSERT(!is_finalized() && position_ < buffer_.length()); + buffer_[position_++] = c; + } + + // Add an entire string to the builder. Uses strlen() internally to + // compute the length of the input string. + void AddString(const char* s) { + AddSubstring(s, StrLength(s)); + } + + // Add the first 'n' characters of the given string 's' to the + // builder. The input string must have enough characters. + void AddSubstring(const char* s, int n) { + ASSERT(!is_finalized() && position_ + n < buffer_.length()); + ASSERT(static_cast(n) <= strlen(s)); + memmove(&buffer_[position_], s, n * kCharSize); + position_ += n; + } + + + // Add character padding to the builder. If count is non-positive, + // nothing is added to the builder. + void AddPadding(char c, int count) { + for (int i = 0; i < count; i++) { + AddCharacter(c); + } + } + + // Finalize the string by 0-terminating it and returning the buffer. + char* Finalize() { + ASSERT(!is_finalized() && position_ < buffer_.length()); + buffer_[position_] = '\0'; + // Make sure nobody managed to add a 0-character to the + // buffer while building the string. + ASSERT(strlen(buffer_.start()) == static_cast(position_)); + position_ = -1; + ASSERT(is_finalized()); + return buffer_.start(); + } + + private: + Vector buffer_; + int position_; + + bool is_finalized() const { return position_ < 0; } + + DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); +}; + +// The type-based aliasing rule allows the compiler to assume that pointers of +// different types (for some definition of different) never alias each other. +// Thus the following code does not work: +// +// float f = foo(); +// int fbits = *(int*)(&f); +// +// The compiler 'knows' that the int pointer can't refer to f since the types +// don't match, so the compiler may cache f in a register, leaving random data +// in fbits. Using C++ style casts makes no difference, however a pointer to +// char data is assumed to alias any other pointer. This is the 'memcpy +// exception'. +// +// Bit_cast uses the memcpy exception to move the bits from a variable of one +// type of a variable of another type. Of course the end result is likely to +// be implementation dependent. Most compilers (gcc-4.2 and MSVC 2005) +// will completely optimize BitCast away. +// +// There is an additional use for BitCast. +// Recent gccs will warn when they see casts that may result in breakage due to +// the type-based aliasing rule. If you have checked that there is no breakage +// you can use BitCast to cast one pointer type to another. This confuses gcc +// enough that it can no longer see that you have cast one pointer type to +// another thus avoiding the warning. +template +inline Dest BitCast(const Source& source) { + // Compile time assertion: sizeof(Dest) == sizeof(Source) + // A compile error here means your Dest and Source have different sizes. + typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1]; + + Dest dest; + memmove(&dest, &source, sizeof(dest)); + return dest; +} + +template +inline Dest BitCast(Source* source) { + return BitCast(reinterpret_cast(source)); +} + +} // namespace double_conversion + +#endif // DOUBLE_CONVERSION_UTILS_H_ From 324818de90b53eed1cdc1faf693f699c02739a29 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Mon, 9 Apr 2012 12:05:11 -0400 Subject: [PATCH 14/14] Bug 614188 - Part 3: build double-conversion as a part of MFBT; r=Waldo --- js/src/Makefile.in | 28 +- js/src/jsnum.cpp | 21 +- js/src/v8-dtoa/README | 34 - js/src/v8-dtoa/cached-powers.h | 119 -- js/src/v8-dtoa/checks.cc | 57 - js/src/v8-dtoa/checks.h | 93 -- js/src/v8-dtoa/conversions.cc | 131 -- js/src/v8-dtoa/conversions.h | 41 - js/src/v8-dtoa/diy-fp.cc | 58 - js/src/v8-dtoa/diy-fp.h | 117 -- js/src/v8-dtoa/double.h | 169 --- js/src/v8-dtoa/dtoa.h | 81 -- js/src/v8-dtoa/fast-dtoa.cc | 505 ------- js/src/v8-dtoa/fast-dtoa.h | 58 - js/src/v8-dtoa/globals.h | 69 - js/src/v8-dtoa/include-v8.h | 59 - js/src/v8-dtoa/platform.cc | 137 -- js/src/v8-dtoa/platform.h | 103 -- js/src/v8-dtoa/powers-ten.h | 2461 -------------------------------- js/src/v8-dtoa/utils.cc | 91 -- js/src/v8-dtoa/utils.h | 165 --- js/src/v8-dtoa/v8-dtoa.cc | 79 - js/src/v8-dtoa/v8.h | 51 - mfbt/Makefile.in | 3 +- mfbt/sources.mk | 22 +- 25 files changed, 37 insertions(+), 4715 deletions(-) delete mode 100644 js/src/v8-dtoa/README delete mode 100644 js/src/v8-dtoa/cached-powers.h delete mode 100644 js/src/v8-dtoa/checks.cc delete mode 100644 js/src/v8-dtoa/checks.h delete mode 100644 js/src/v8-dtoa/conversions.cc delete mode 100644 js/src/v8-dtoa/conversions.h delete mode 100644 js/src/v8-dtoa/diy-fp.cc delete mode 100644 js/src/v8-dtoa/diy-fp.h delete mode 100644 js/src/v8-dtoa/double.h delete mode 100644 js/src/v8-dtoa/dtoa.h delete mode 100644 js/src/v8-dtoa/fast-dtoa.cc delete mode 100644 js/src/v8-dtoa/fast-dtoa.h delete mode 100644 js/src/v8-dtoa/globals.h delete mode 100644 js/src/v8-dtoa/include-v8.h delete mode 100644 js/src/v8-dtoa/platform.cc delete mode 100644 js/src/v8-dtoa/platform.h delete mode 100644 js/src/v8-dtoa/powers-ten.h delete mode 100644 js/src/v8-dtoa/utils.cc delete mode 100644 js/src/v8-dtoa/utils.h delete mode 100644 js/src/v8-dtoa/v8-dtoa.cc delete mode 100644 js/src/v8-dtoa/v8.h diff --git a/js/src/Makefile.in b/js/src/Makefile.in index 8473c5095c45..3f57516bb86d 100644 --- a/js/src/Makefile.in +++ b/js/src/Makefile.in @@ -256,8 +256,9 @@ EXPORTS_js = \ ############################################### # BEGIN include sources for low-level code shared with mfbt # -VPATH += $(srcdir)/../../mfbt -include $(srcdir)/../../mfbt/exported_headers.mk +MFBT_ROOT = $(srcdir)/../../mfbt +VPATH += $(MFBT_ROOT) +include $(MFBT_ROOT)/exported_headers.mk ifdef ENABLE_METHODJIT @@ -319,25 +320,6 @@ endif endif -############################################### -# BEGIN include sources for V8 dtoa -# -VPATH += $(srcdir)/v8-dtoa \ - $(NONE) - -CPPSRCS += checks.cc \ - conversions.cc \ - diy-fp.cc \ - v8-dtoa.cc \ - fast-dtoa.cc \ - platform.cc \ - utils.cc \ - $(NONE) - -# -# END enclude sources for V8 dtoa -############################################# - # For architectures without YARR JIT, PCRE is faster than the YARR # interpreter (bug 684559). @@ -451,6 +433,8 @@ endif endif # JS_HAS_CTYPES +LOCAL_INCLUDES += -I$(MFBT_ROOT)/double-conversion + ifdef HAVE_DTRACE INSTALLED_HEADERS += \ $(CURDIR)/javascript-trace.h \ @@ -494,7 +478,7 @@ include $(topsrcdir)/config/config.mk ifeq (,$(MOZ_GLUE_PROGRAM_LDFLAGS)) # When building standalone, we need to include mfbt sources, and to declare # "exported" mfbt symbols on its behalf when we use its headers. -include $(srcdir)/../../mfbt/sources.mk +include $(MFBT_ROOT)/sources.mk DEFINES += -DIMPL_MFBT endif diff --git a/js/src/jsnum.cpp b/js/src/jsnum.cpp index 750b03094d83..d6e13e8549ce 100644 --- a/js/src/jsnum.cpp +++ b/js/src/jsnum.cpp @@ -53,6 +53,9 @@ #include #include "mozilla/RangedPtr.h" +#include "double-conversion.h" +// Avoid warnings about ASSERT being defined by the assembler as well. +#undef ASSERT #include "jstypes.h" #include "jsutil.h" @@ -1053,12 +1056,6 @@ js_InitNumberClass(JSContext *cx, JSObject *obj) return numberProto; } -namespace v8 { -namespace internal { -extern char* DoubleToCString(double v, char* buffer, int buflen); -} -} - namespace js { static char * @@ -1079,14 +1076,12 @@ FracNumberToCString(JSContext *cx, ToCStringBuf *cbuf, double d, int base = 10) * * Printing floating-point numbers quickly and accurately with integers. * Florian Loitsch, PLDI 2010. - * - * It fails on a small number of cases, whereupon we fall back to - * js_dtostr() (which uses David Gay's dtoa). */ - numStr = v8::internal::DoubleToCString(d, cbuf->sbuf, cbuf->sbufSize); - if (!numStr) - numStr = js_dtostr(cx->runtime->dtoaState, cbuf->sbuf, cbuf->sbufSize, - DTOSTR_STANDARD, 0, d); + const double_conversion::DoubleToStringConverter &converter + = double_conversion::DoubleToStringConverter::EcmaScriptConverter(); + double_conversion::StringBuilder builder(cbuf->sbuf, cbuf->sbufSize); + converter.ToShortest(d, &builder); + numStr = builder.Finalize(); } else { numStr = cbuf->dbuf = js_dtobasestr(cx->runtime->dtoaState, base, d); } diff --git a/js/src/v8-dtoa/README b/js/src/v8-dtoa/README deleted file mode 100644 index 7199f56b71dd..000000000000 --- a/js/src/v8-dtoa/README +++ /dev/null @@ -1,34 +0,0 @@ -This directory contains V8's fast dtoa conversion code. The V8 revision -imported was: - - Repository Root: http://v8.googlecode.com/svn - Repository UUID: ce2b1a6d-e550-0410-aec6-3dcde31c8c00 - Revision: 5322 - -The function of interest, which is called by SpiderMonkey, is -conversions.cc:DoubleToCString(). This is called from jsnum.cpp to provide a -fast Number.toString(10) implementation. - -A great deal of code has been removed from the imported files. The -remaining code is more or less the bare minimum required to support this -function in a straightforward, standalone manner. - -Two related functions in V8 are DoubleToExponentialCString() and -DoubleToPrecisionString(), which can be used to implement -Number.toExponential() and Number.toPrecision(). They have not been imported; -they both call dtoa() and so are unlikely to be noticeably faster than the -existing SpiderMonkey equivalents. - -Another related function in V8 is DoubleToRadixCString(), which can be used to -implement Number.toString(base), where base != 10. This has not been imported; -it may well be faster than SpiderMonkey's implementation, but V8 generates its -own definition of the modulo() function on Win64 and importing this would -require also importing large chunks of the assembler, which is not worthwhile. - -Yet another related function in V8 is DoubleToFixedCString(), which can be used -to implement Number.toFixed(). This has not been imported as it was measured -as slower than SpiderMonkey's version. - -Comments preceded by the string "MOZ: " indicate places where the code has -been changed significantly from the original code. - diff --git a/js/src/v8-dtoa/cached-powers.h b/js/src/v8-dtoa/cached-powers.h deleted file mode 100644 index 314ccca3c453..000000000000 --- a/js/src/v8-dtoa/cached-powers.h +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright 2010 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef V8_CACHED_POWERS_H_ -#define V8_CACHED_POWERS_H_ - -#include "diy-fp.h" - -namespace v8 { -namespace internal { - -struct CachedPower { - uint64_t significand; - int16_t binary_exponent; - int16_t decimal_exponent; -}; - -// The following defines implement the interface between this file and the -// generated 'powers_ten.h'. -// GRISU_CACHE_NAME(1) contains all possible cached powers. -// GRISU_CACHE_NAME(i) contains GRISU_CACHE_NAME(1) where only every 'i'th -// element is kept. More formally GRISU_CACHE_NAME(i) contains the elements j*i -// with 0 <= j < k with k such that j*k < the size of GRISU_CACHE_NAME(1). -// The higher 'i' is the fewer elements we use. -// Given that there are less elements, the exponent-distance between two -// elements in the cache grows. The variable GRISU_CACHE_MAX_DISTANCE(i) stores -// the maximum distance between two elements. -#define GRISU_CACHE_STRUCT CachedPower -#define GRISU_CACHE_NAME(i) kCachedPowers##i -#define GRISU_CACHE_MAX_DISTANCE(i) kCachedPowersMaxDistance##i -#define GRISU_CACHE_OFFSET kCachedPowerOffset -#define GRISU_UINT64_C V8_2PART_UINT64_C -// The following include imports the precompiled cached powers. -#include "powers-ten.h" // NOLINT - -static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10) - -// We can't use a function since we reference variables depending on the 'i'. -// This way the compiler is able to see at compile time that only one -// cache-array variable is used and thus can remove all the others. -#define COMPUTE_FOR_CACHE(i) \ - if (!found && (gamma - alpha + 1 >= GRISU_CACHE_MAX_DISTANCE(i))) { \ - int kQ = DiyFp::kSignificandSize; \ - double k = ceiling((alpha - e + kQ - 1) * kD_1_LOG2_10); \ - int index = (GRISU_CACHE_OFFSET + static_cast(k) - 1) / i + 1; \ - cached_power = GRISU_CACHE_NAME(i)[index]; \ - found = true; \ - } \ - -static void GetCachedPower(int e, int alpha, int gamma, int* mk, DiyFp* c_mk) { - // The following if statement should be optimized by the compiler so that only - // one array is referenced and the others are not included in the object file. - bool found = false; - CachedPower cached_power; - COMPUTE_FOR_CACHE(20); - COMPUTE_FOR_CACHE(19); - COMPUTE_FOR_CACHE(18); - COMPUTE_FOR_CACHE(17); - COMPUTE_FOR_CACHE(16); - COMPUTE_FOR_CACHE(15); - COMPUTE_FOR_CACHE(14); - COMPUTE_FOR_CACHE(13); - COMPUTE_FOR_CACHE(12); - COMPUTE_FOR_CACHE(11); - COMPUTE_FOR_CACHE(10); - COMPUTE_FOR_CACHE(9); - COMPUTE_FOR_CACHE(8); - COMPUTE_FOR_CACHE(7); - COMPUTE_FOR_CACHE(6); - COMPUTE_FOR_CACHE(5); - COMPUTE_FOR_CACHE(4); - COMPUTE_FOR_CACHE(3); - COMPUTE_FOR_CACHE(2); - COMPUTE_FOR_CACHE(1); - if (!found) { - UNIMPLEMENTED(); - // Silence compiler warnings. - cached_power.significand = 0; - cached_power.binary_exponent = 0; - cached_power.decimal_exponent = 0; - } - *c_mk = DiyFp(cached_power.significand, cached_power.binary_exponent); - *mk = cached_power.decimal_exponent; - ASSERT((alpha <= c_mk->e() + e) && (c_mk->e() + e <= gamma)); -} -#undef GRISU_REDUCTION -#undef GRISU_CACHE_STRUCT -#undef GRISU_CACHE_NAME -#undef GRISU_CACHE_MAX_DISTANCE -#undef GRISU_CACHE_OFFSET -#undef GRISU_UINT64_C - -} } // namespace v8::internal - -#endif // V8_CACHED_POWERS_H_ diff --git a/js/src/v8-dtoa/checks.cc b/js/src/v8-dtoa/checks.cc deleted file mode 100644 index 592fe20111f3..000000000000 --- a/js/src/v8-dtoa/checks.cc +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2006-2008 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include -#include - -#include "v8.h" - -static int fatal_error_handler_nesting_depth = 0; - -// Contains protection against recursive calls (faults while handling faults). -extern "C" void V8_Fatal(const char* file, int line, const char* format, ...) { - fflush(stdout); - fflush(stderr); - fatal_error_handler_nesting_depth++; - // First time we try to print an error message - // - // MOZ: lots of calls to printing functions within v8::internal::OS were - // replaced with simpler standard C calls, to avoid pulling in lots of - // platform-specific code. As a result, in some cases the error message may - // not be printed as well or at all. - if (fatal_error_handler_nesting_depth < 2) { - fprintf(stderr, "\n\n#\n# Fatal error in %s, line %d\n# ", file, line); - va_list arguments; - va_start(arguments, format); - vfprintf(stderr, format, arguments); - va_end(arguments); - fprintf(stderr, "\n#\n\n"); - } - - i::OS::Abort(); -} - diff --git a/js/src/v8-dtoa/checks.h b/js/src/v8-dtoa/checks.h deleted file mode 100644 index 59c0e14265d0..000000000000 --- a/js/src/v8-dtoa/checks.h +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2006-2008 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef V8_CHECKS_H_ -#define V8_CHECKS_H_ - -#include - -extern "C" void V8_Fatal(const char* file, int line, const char* format, ...); - -// The FATAL, UNREACHABLE and UNIMPLEMENTED macros are useful during -// development, but they should not be relied on in the final product. - -#ifdef DEBUG -#define FATAL(msg) \ - V8_Fatal(__FILE__, __LINE__, "%s", (msg)) -#define UNIMPLEMENTED() \ - V8_Fatal(__FILE__, __LINE__, "unimplemented code") -#define UNREACHABLE() \ - V8_Fatal(__FILE__, __LINE__, "unreachable code") -#else -#define FATAL(msg) \ - V8_Fatal("", 0, "%s", (msg)) -#define UNIMPLEMENTED() \ - V8_Fatal("", 0, "unimplemented code") -#define UNREACHABLE() ((void) 0) -#endif - -// Used by the CHECK macro -- should not be called directly. -static inline void CheckHelper(const char* file, - int line, - const char* source, - bool condition) { - if (!condition) - V8_Fatal(file, line, source); -} - - -// The CHECK macro checks that the given condition is true; if not, it -// prints a message to stderr and aborts. -#define CHECK(condition) ::CheckHelper(__FILE__, __LINE__, #condition, condition) - - -// Helper function used by the CHECK_EQ function when given int -// arguments. Should not be called directly. -static inline void CheckEqualsHelper(const char* file, int line, - const char* expected_source, int expected, - const char* value_source, int value) { - if (expected != value) { - V8_Fatal(file, line, - "CHECK_EQ(%s, %s) failed\n# Expected: %i\n# Found: %i", - expected_source, value_source, expected, value); - } -} - - -#define CHECK_EQ(expected, value) CheckEqualsHelper(__FILE__, __LINE__, \ - #expected, expected, #value, value) - - -// The ASSERT macro is equivalent to CHECK except that it only -// generates code in debug builds. -#ifdef DEBUG -#define ASSERT(condition) CHECK(condition) -#else -#define ASSERT(condition) ((void) 0) -#endif - -#endif // V8_CHECKS_H_ diff --git a/js/src/v8-dtoa/conversions.cc b/js/src/v8-dtoa/conversions.cc deleted file mode 100644 index 4ff10b7c6a38..000000000000 --- a/js/src/v8-dtoa/conversions.cc +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2006-2008 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include - -#include "v8.h" -#include "dtoa.h" - -namespace v8 { -namespace internal { - -// MOZ: The return type was changed from 'const char*' to 'char*' to match the -// usage within SpiderMonkey. -// -// MOZ: The arguments were modified to use a char buffer instead of -// v8::internal::Vector, to save SpiderMonkey from having to know about that -// type. -// -// MOZ: The function was modified to return NULL when it needs to fall back to -// Gay's dtoa, rather than calling Gay's dtoa itself. That's because -// SpiderMonkey already has its own copy of Gay's dtoa. -// -char* DoubleToCString(double v, char* buffer, int buflen) { - StringBuilder builder(buffer, buflen); - - switch (fpclassify(v)) { - case FP_NAN: - builder.AddString("NaN"); - break; - - case FP_INFINITE: - if (v < 0.0) { - builder.AddString("-Infinity"); - } else { - builder.AddString("Infinity"); - } - break; - - case FP_ZERO: - builder.AddCharacter('0'); - break; - - default: { - int decimal_point; - int sign; - char* decimal_rep; - //bool used_gay_dtoa = false; MOZ: see above - const int kV8DtoaBufferCapacity = kBase10MaximalLength + 1; - char v8_dtoa_buffer[kV8DtoaBufferCapacity]; - int length; - - if (DoubleToAscii(v, DTOA_SHORTEST, 0, - Vector(v8_dtoa_buffer, kV8DtoaBufferCapacity), - &sign, &length, &decimal_point)) { - decimal_rep = v8_dtoa_buffer; - } else { - return NULL; // MOZ: see above - //decimal_rep = dtoa(v, 0, 0, &decimal_point, &sign, NULL); - //used_gay_dtoa = true; - //length = StrLength(decimal_rep); - } - - if (sign) builder.AddCharacter('-'); - - if (length <= decimal_point && decimal_point <= 21) { - // ECMA-262 section 9.8.1 step 6. - builder.AddString(decimal_rep); - builder.AddPadding('0', decimal_point - length); - - } else if (0 < decimal_point && decimal_point <= 21) { - // ECMA-262 section 9.8.1 step 7. - builder.AddSubstring(decimal_rep, decimal_point); - builder.AddCharacter('.'); - builder.AddString(decimal_rep + decimal_point); - - } else if (decimal_point <= 0 && decimal_point > -6) { - // ECMA-262 section 9.8.1 step 8. - builder.AddString("0."); - builder.AddPadding('0', -decimal_point); - builder.AddString(decimal_rep); - - } else { - // ECMA-262 section 9.8.1 step 9 and 10 combined. - builder.AddCharacter(decimal_rep[0]); - if (length != 1) { - builder.AddCharacter('.'); - builder.AddString(decimal_rep + 1); - } - builder.AddCharacter('e'); - builder.AddCharacter((decimal_point >= 0) ? '+' : '-'); - int exponent = decimal_point - 1; - if (exponent < 0) exponent = -exponent; - // MOZ: This was a call to 'AddFormatted("%d", exponent)', which - // called onto vsnprintf(). Because this was the only call to - // AddFormatted in the imported code, it was replaced with this call - // to AddInteger, which is faster and doesn't require any - // platform-specific code. - builder.AddInteger(exponent); - } - - //if (used_gay_dtoa) freedtoa(decimal_rep); MOZ: see above - } - } - return builder.Finalize(); -} - -} } // namespace v8::internal diff --git a/js/src/v8-dtoa/conversions.h b/js/src/v8-dtoa/conversions.h deleted file mode 100644 index bbd60832a436..000000000000 --- a/js/src/v8-dtoa/conversions.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2006-2008 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef V8_CONVERSIONS_H_ -#define V8_CONVERSIONS_H_ - -namespace v8 { -namespace internal { - -// Converts a double to a string value according to ECMA-262 9.8.1. -// The buffer should be large enough for any floating point number. -// 100 characters is enough. -const char* DoubleToCString(double value, char* buffer, int buflen); - -} } // namespace v8::internal - -#endif // V8_CONVERSIONS_H_ diff --git a/js/src/v8-dtoa/diy-fp.cc b/js/src/v8-dtoa/diy-fp.cc deleted file mode 100644 index c54bd1d326f3..000000000000 --- a/js/src/v8-dtoa/diy-fp.cc +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2010 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include "v8.h" - -#include "diy-fp.h" - -namespace v8 { -namespace internal { - -void DiyFp::Multiply(const DiyFp& other) { - // Simply "emulates" a 128 bit multiplication. - // However: the resulting number only contains 64 bits. The least - // significant 64 bits are only used for rounding the most significant 64 - // bits. - const uint64_t kM32 = 0xFFFFFFFFu; - uint64_t a = f_ >> 32; - uint64_t b = f_ & kM32; - uint64_t c = other.f_ >> 32; - uint64_t d = other.f_ & kM32; - uint64_t ac = a * c; - uint64_t bc = b * c; - uint64_t ad = a * d; - uint64_t bd = b * d; - uint64_t tmp = (bd >> 32) + (ad & kM32) + (bc & kM32); - // By adding 1U << 31 to tmp we round the final result. - // Halfway cases will be round up. - tmp += 1U << 31; - uint64_t result_f = ac + (ad >> 32) + (bc >> 32) + (tmp >> 32); - e_ += other.e_ + 64; - f_ = result_f; -} - -} } // namespace v8::internal diff --git a/js/src/v8-dtoa/diy-fp.h b/js/src/v8-dtoa/diy-fp.h deleted file mode 100644 index cfe05ef7428b..000000000000 --- a/js/src/v8-dtoa/diy-fp.h +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2010 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef V8_DIY_FP_H_ -#define V8_DIY_FP_H_ - -namespace v8 { -namespace internal { - -// This "Do It Yourself Floating Point" class implements a floating-point number -// with a uint64 significand and an int exponent. Normalized DiyFp numbers will -// have the most significant bit of the significand set. -// Multiplication and Subtraction do not normalize their results. -// DiyFp are not designed to contain special doubles (NaN and Infinity). -class DiyFp { - public: - static const int kSignificandSize = 64; - - DiyFp() : f_(0), e_(0) {} - DiyFp(uint64_t f, int e) : f_(f), e_(e) {} - - // this = this - other. - // The exponents of both numbers must be the same and the significand of this - // must be bigger than the significand of other. - // The result will not be normalized. - void Subtract(const DiyFp& other) { - ASSERT(e_ == other.e_); - ASSERT(f_ >= other.f_); - f_ -= other.f_; - } - - // Returns a - b. - // The exponents of both numbers must be the same and this must be bigger - // than other. The result will not be normalized. - static DiyFp Minus(const DiyFp& a, const DiyFp& b) { - DiyFp result = a; - result.Subtract(b); - return result; - } - - - // this = this * other. - void Multiply(const DiyFp& other); - - // returns a * b; - static DiyFp Times(const DiyFp& a, const DiyFp& b) { - DiyFp result = a; - result.Multiply(b); - return result; - } - - void Normalize() { - ASSERT(f_ != 0); - uint64_t f = f_; - int e = e_; - - // This method is mainly called for normalizing boundaries. In general - // boundaries need to be shifted by 10 bits. We thus optimize for this case. - const uint64_t k10MSBits = V8_2PART_UINT64_C(0xFFC00000, 00000000); - while ((f & k10MSBits) == 0) { - f <<= 10; - e -= 10; - } - while ((f & kUint64MSB) == 0) { - f <<= 1; - e--; - } - f_ = f; - e_ = e; - } - - static DiyFp Normalize(const DiyFp& a) { - DiyFp result = a; - result.Normalize(); - return result; - } - - uint64_t f() const { return f_; } - int e() const { return e_; } - - void set_f(uint64_t new_value) { f_ = new_value; } - void set_e(int new_value) { e_ = new_value; } - - private: - static const uint64_t kUint64MSB = V8_2PART_UINT64_C(0x80000000, 00000000); - - uint64_t f_; - int e_; -}; - -} } // namespace v8::internal - -#endif // V8_DIY_FP_H_ diff --git a/js/src/v8-dtoa/double.h b/js/src/v8-dtoa/double.h deleted file mode 100644 index 65f8c9444b0b..000000000000 --- a/js/src/v8-dtoa/double.h +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright 2010 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef V8_DOUBLE_H_ -#define V8_DOUBLE_H_ - -#include "diy-fp.h" - -namespace v8 { -namespace internal { - -// We assume that doubles and uint64_t have the same endianness. -static uint64_t double_to_uint64(double d) { return BitCast(d); } -static double uint64_to_double(uint64_t d64) { return BitCast(d64); } - -// Helper functions for doubles. -class Double { - public: - static const uint64_t kSignMask = V8_2PART_UINT64_C(0x80000000, 00000000); - static const uint64_t kExponentMask = V8_2PART_UINT64_C(0x7FF00000, 00000000); - static const uint64_t kSignificandMask = - V8_2PART_UINT64_C(0x000FFFFF, FFFFFFFF); - static const uint64_t kHiddenBit = V8_2PART_UINT64_C(0x00100000, 00000000); - - Double() : d64_(0) {} - explicit Double(double d) : d64_(double_to_uint64(d)) {} - explicit Double(uint64_t d64) : d64_(d64) {} - - DiyFp AsDiyFp() const { - ASSERT(!IsSpecial()); - return DiyFp(Significand(), Exponent()); - } - - // this->Significand() must not be 0. - DiyFp AsNormalizedDiyFp() const { - uint64_t f = Significand(); - int e = Exponent(); - - ASSERT(f != 0); - - // The current double could be a denormal. - while ((f & kHiddenBit) == 0) { - f <<= 1; - e--; - } - // Do the final shifts in one go. Don't forget the hidden bit (the '-1'). - f <<= DiyFp::kSignificandSize - kSignificandSize - 1; - e -= DiyFp::kSignificandSize - kSignificandSize - 1; - return DiyFp(f, e); - } - - // Returns the double's bit as uint64. - uint64_t AsUint64() const { - return d64_; - } - - int Exponent() const { - if (IsDenormal()) return kDenormalExponent; - - uint64_t d64 = AsUint64(); - int biased_e = static_cast((d64 & kExponentMask) >> kSignificandSize); - return biased_e - kExponentBias; - } - - uint64_t Significand() const { - uint64_t d64 = AsUint64(); - uint64_t significand = d64 & kSignificandMask; - if (!IsDenormal()) { - return significand + kHiddenBit; - } else { - return significand; - } - } - - // Returns true if the double is a denormal. - bool IsDenormal() const { - uint64_t d64 = AsUint64(); - return (d64 & kExponentMask) == 0; - } - - // We consider denormals not to be special. - // Hence only Infinity and NaN are special. - bool IsSpecial() const { - uint64_t d64 = AsUint64(); - return (d64 & kExponentMask) == kExponentMask; - } - - bool IsNan() const { - uint64_t d64 = AsUint64(); - return ((d64 & kExponentMask) == kExponentMask) && - ((d64 & kSignificandMask) != 0); - } - - - bool IsInfinite() const { - uint64_t d64 = AsUint64(); - return ((d64 & kExponentMask) == kExponentMask) && - ((d64 & kSignificandMask) == 0); - } - - - int Sign() const { - uint64_t d64 = AsUint64(); - return (d64 & kSignMask) == 0? 1: -1; - } - - - // Returns the two boundaries of this. - // The bigger boundary (m_plus) is normalized. The lower boundary has the same - // exponent as m_plus. - void NormalizedBoundaries(DiyFp* out_m_minus, DiyFp* out_m_plus) const { - DiyFp v = this->AsDiyFp(); - bool significand_is_zero = (v.f() == kHiddenBit); - DiyFp m_plus = DiyFp::Normalize(DiyFp((v.f() << 1) + 1, v.e() - 1)); - DiyFp m_minus; - if (significand_is_zero && v.e() != kDenormalExponent) { - // The boundary is closer. Think of v = 1000e10 and v- = 9999e9. - // Then the boundary (== (v - v-)/2) is not just at a distance of 1e9 but - // at a distance of 1e8. - // The only exception is for the smallest normal: the largest denormal is - // at the same distance as its successor. - // Note: denormals have the same exponent as the smallest normals. - m_minus = DiyFp((v.f() << 2) - 1, v.e() - 2); - } else { - m_minus = DiyFp((v.f() << 1) - 1, v.e() - 1); - } - m_minus.set_f(m_minus.f() << (m_minus.e() - m_plus.e())); - m_minus.set_e(m_plus.e()); - *out_m_plus = m_plus; - *out_m_minus = m_minus; - } - - double value() const { return uint64_to_double(d64_); } - - private: - static const int kSignificandSize = 52; // Excludes the hidden bit. - static const int kExponentBias = 0x3FF + kSignificandSize; - static const int kDenormalExponent = -kExponentBias + 1; - - uint64_t d64_; -}; - -} } // namespace v8::internal - -#endif // V8_DOUBLE_H_ diff --git a/js/src/v8-dtoa/dtoa.h b/js/src/v8-dtoa/dtoa.h deleted file mode 100644 index be0d5456b23e..000000000000 --- a/js/src/v8-dtoa/dtoa.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2010 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef V8_DTOA_H_ -#define V8_DTOA_H_ - -namespace v8 { -namespace internal { - -enum DtoaMode { - // 0.9999999999999999 becomes 0.1 - DTOA_SHORTEST, - // Fixed number of digits after the decimal point. - // For instance fixed(0.1, 4) becomes 0.1000 - // If the input number is big, the output will be big. - DTOA_FIXED, - // Fixed number of digits (independent of the decimal point). - DTOA_PRECISION -}; - -// The maximal length of digits a double can have in base 10. -// Note that DoubleToAscii null-terminates its input. So the given buffer should -// be at least kBase10MaximalLength + 1 characters long. -static const int kBase10MaximalLength = 17; - -// Converts the given double 'v' to ascii. -// The result should be interpreted as buffer * 10^(point-length). -// -// The output depends on the given mode: -// - SHORTEST: produce the least amount of digits for which the internal -// identity requirement is still satisfied. If the digits are printed -// (together with the correct exponent) then reading this number will give -// 'v' again. The buffer will choose the representation that is closest to -// 'v'. If there are two at the same distance, than the one farther away -// from 0 is chosen (halfway cases - ending with 5 - are rounded up). -// In this mode the 'requested_digits' parameter is ignored. -// - FIXED: produces digits necessary to print a given number with -// 'requested_digits' digits after the decimal point. The produced digits -// might be too short in which case the caller has to fill the gaps with '0's. -// Example: toFixed(0.001, 5) is allowed to return buffer="1", point=-2. -// Halfway cases are rounded towards +/-Infinity (away from 0). The call -// toFixed(0.15, 2) thus returns buffer="2", point=0. -// The returned buffer may contain digits that would be truncated from the -// shortest representation of the input. -// - PRECISION: produces 'requested_digits' where the first digit is not '0'. -// Even though the length of produced digits usually equals -// 'requested_digits', the function is allowed to return fewer digits, in -// which case the caller has to fill the missing digits with '0's. -// Halfway cases are again rounded away from 0. -// 'DoubleToAscii' expects the given buffer to be big enough to hold all digits -// and a terminating null-character. -bool DoubleToAscii(double v, DtoaMode mode, int requested_digits, - Vector buffer, int* sign, int* length, int* point); - -} } // namespace v8::internal - -#endif // V8_DTOA_H_ diff --git a/js/src/v8-dtoa/fast-dtoa.cc b/js/src/v8-dtoa/fast-dtoa.cc deleted file mode 100644 index b4b7be053fb2..000000000000 --- a/js/src/v8-dtoa/fast-dtoa.cc +++ /dev/null @@ -1,505 +0,0 @@ -// Copyright 2010 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include "v8.h" - -#include "fast-dtoa.h" - -#include "cached-powers.h" -#include "diy-fp.h" -#include "double.h" - -namespace v8 { -namespace internal { - -// The minimal and maximal target exponent define the range of w's binary -// exponent, where 'w' is the result of multiplying the input by a cached power -// of ten. -// -// A different range might be chosen on a different platform, to optimize digit -// generation, but a smaller range requires more powers of ten to be cached. -static const int minimal_target_exponent = -60; -static const int maximal_target_exponent = -32; - - -// Adjusts the last digit of the generated number, and screens out generated -// solutions that may be inaccurate. A solution may be inaccurate if it is -// outside the safe interval, or if we ctannot prove that it is closer to the -// input than a neighboring representation of the same length. -// -// Input: * buffer containing the digits of too_high / 10^kappa -// * the buffer's length -// * distance_too_high_w == (too_high - w).f() * unit -// * unsafe_interval == (too_high - too_low).f() * unit -// * rest = (too_high - buffer * 10^kappa).f() * unit -// * ten_kappa = 10^kappa * unit -// * unit = the common multiplier -// Output: returns true if the buffer is guaranteed to contain the closest -// representable number to the input. -// Modifies the generated digits in the buffer to approach (round towards) w. -bool RoundWeed(Vector buffer, - int length, - uint64_t distance_too_high_w, - uint64_t unsafe_interval, - uint64_t rest, - uint64_t ten_kappa, - uint64_t unit) { - uint64_t small_distance = distance_too_high_w - unit; - uint64_t big_distance = distance_too_high_w + unit; - // Let w_low = too_high - big_distance, and - // w_high = too_high - small_distance. - // Note: w_low < w < w_high - // - // The real w (* unit) must lie somewhere inside the interval - // ]w_low; w_low[ (often written as "(w_low; w_low)") - - // Basically the buffer currently contains a number in the unsafe interval - // ]too_low; too_high[ with too_low < w < too_high - // - // too_high - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // ^v 1 unit ^ ^ ^ ^ - // boundary_high --------------------- . . . . - // ^v 1 unit . . . . - // - - - - - - - - - - - - - - - - - - - + - - + - - - - - - . . - // . . ^ . . - // . big_distance . . . - // . . . . rest - // small_distance . . . . - // v . . . . - // w_high - - - - - - - - - - - - - - - - - - . . . . - // ^v 1 unit . . . . - // w ---------------------------------------- . . . . - // ^v 1 unit v . . . - // w_low - - - - - - - - - - - - - - - - - - - - - . . . - // . . v - // buffer --------------------------------------------------+-------+-------- - // . . - // safe_interval . - // v . - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - . - // ^v 1 unit . - // boundary_low ------------------------- unsafe_interval - // ^v 1 unit v - // too_low - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - // - // Note that the value of buffer could lie anywhere inside the range too_low - // to too_high. - // - // boundary_low, boundary_high and w are approximations of the real boundaries - // and v (the input number). They are guaranteed to be precise up to one unit. - // In fact the error is guaranteed to be strictly less than one unit. - // - // Anything that lies outside the unsafe interval is guaranteed not to round - // to v when read again. - // Anything that lies inside the safe interval is guaranteed to round to v - // when read again. - // If the number inside the buffer lies inside the unsafe interval but not - // inside the safe interval then we simply do not know and bail out (returning - // false). - // - // Similarly we have to take into account the imprecision of 'w' when rounding - // the buffer. If we have two potential representations we need to make sure - // that the chosen one is closer to w_low and w_high since v can be anywhere - // between them. - // - // By generating the digits of too_high we got the largest (closest to - // too_high) buffer that is still in the unsafe interval. In the case where - // w_high < buffer < too_high we try to decrement the buffer. - // This way the buffer approaches (rounds towards) w. - // There are 3 conditions that stop the decrementation process: - // 1) the buffer is already below w_high - // 2) decrementing the buffer would make it leave the unsafe interval - // 3) decrementing the buffer would yield a number below w_high and farther - // away than the current number. In other words: - // (buffer{-1} < w_high) && w_high - buffer{-1} > buffer - w_high - // Instead of using the buffer directly we use its distance to too_high. - // Conceptually rest ~= too_high - buffer - while (rest < small_distance && // Negated condition 1 - unsafe_interval - rest >= ten_kappa && // Negated condition 2 - (rest + ten_kappa < small_distance || // buffer{-1} > w_high - small_distance - rest >= rest + ten_kappa - small_distance)) { - buffer[length - 1]--; - rest += ten_kappa; - } - - // We have approached w+ as much as possible. We now test if approaching w- - // would require changing the buffer. If yes, then we have two possible - // representations close to w, but we cannot decide which one is closer. - if (rest < big_distance && - unsafe_interval - rest >= ten_kappa && - (rest + ten_kappa < big_distance || - big_distance - rest > rest + ten_kappa - big_distance)) { - return false; - } - - // Weeding test. - // The safe interval is [too_low + 2 ulp; too_high - 2 ulp] - // Since too_low = too_high - unsafe_interval this is equivalent to - // [too_high - unsafe_interval + 4 ulp; too_high - 2 ulp] - // Conceptually we have: rest ~= too_high - buffer - return (2 * unit <= rest) && (rest <= unsafe_interval - 4 * unit); -} - - - -static const uint32_t kTen4 = 10000; -static const uint32_t kTen5 = 100000; -static const uint32_t kTen6 = 1000000; -static const uint32_t kTen7 = 10000000; -static const uint32_t kTen8 = 100000000; -static const uint32_t kTen9 = 1000000000; - -// Returns the biggest power of ten that is less than or equal than the given -// number. We furthermore receive the maximum number of bits 'number' has. -// If number_bits == 0 then 0^-1 is returned -// The number of bits must be <= 32. -// Precondition: (1 << number_bits) <= number < (1 << (number_bits + 1)). -static void BiggestPowerTen(uint32_t number, - int number_bits, - uint32_t* power, - int* exponent) { - switch (number_bits) { - case 32: - case 31: - case 30: - if (kTen9 <= number) { - *power = kTen9; - *exponent = 9; - break; - } // else fallthrough - case 29: - case 28: - case 27: - if (kTen8 <= number) { - *power = kTen8; - *exponent = 8; - break; - } // else fallthrough - case 26: - case 25: - case 24: - if (kTen7 <= number) { - *power = kTen7; - *exponent = 7; - break; - } // else fallthrough - case 23: - case 22: - case 21: - case 20: - if (kTen6 <= number) { - *power = kTen6; - *exponent = 6; - break; - } // else fallthrough - case 19: - case 18: - case 17: - if (kTen5 <= number) { - *power = kTen5; - *exponent = 5; - break; - } // else fallthrough - case 16: - case 15: - case 14: - if (kTen4 <= number) { - *power = kTen4; - *exponent = 4; - break; - } // else fallthrough - case 13: - case 12: - case 11: - case 10: - if (1000 <= number) { - *power = 1000; - *exponent = 3; - break; - } // else fallthrough - case 9: - case 8: - case 7: - if (100 <= number) { - *power = 100; - *exponent = 2; - break; - } // else fallthrough - case 6: - case 5: - case 4: - if (10 <= number) { - *power = 10; - *exponent = 1; - break; - } // else fallthrough - case 3: - case 2: - case 1: - if (1 <= number) { - *power = 1; - *exponent = 0; - break; - } // else fallthrough - case 0: - *power = 0; - *exponent = -1; - break; - default: - // Following assignments are here to silence compiler warnings. - *power = 0; - *exponent = 0; - UNREACHABLE(); - } -} - - -// Generates the digits of input number w. -// w is a floating-point number (DiyFp), consisting of a significand and an -// exponent. Its exponent is bounded by minimal_target_exponent and -// maximal_target_exponent. -// Hence -60 <= w.e() <= -32. -// -// Returns false if it fails, in which case the generated digits in the buffer -// should not be used. -// Preconditions: -// * low, w and high are correct up to 1 ulp (unit in the last place). That -// is, their error must be less that a unit of their last digits. -// * low.e() == w.e() == high.e() -// * low < w < high, and taking into account their error: low~ <= high~ -// * minimal_target_exponent <= w.e() <= maximal_target_exponent -// Postconditions: returns false if procedure fails. -// otherwise: -// * buffer is not null-terminated, but len contains the number of digits. -// * buffer contains the shortest possible decimal digit-sequence -// such that LOW < buffer * 10^kappa < HIGH, where LOW and HIGH are the -// correct values of low and high (without their error). -// * if more than one decimal representation gives the minimal number of -// decimal digits then the one closest to W (where W is the correct value -// of w) is chosen. -// Remark: this procedure takes into account the imprecision of its input -// numbers. If the precision is not enough to guarantee all the postconditions -// then false is returned. This usually happens rarely (~0.5%). -// -// Say, for the sake of example, that -// w.e() == -48, and w.f() == 0x1234567890abcdef -// w's value can be computed by w.f() * 2^w.e() -// We can obtain w's integral digits by simply shifting w.f() by -w.e(). -// -> w's integral part is 0x1234 -// w's fractional part is therefore 0x567890abcdef. -// Printing w's integral part is easy (simply print 0x1234 in decimal). -// In order to print its fraction we repeatedly multiply the fraction by 10 and -// get each digit. Example the first digit after the point would be computed by -// (0x567890abcdef * 10) >> 48. -> 3 -// The whole thing becomes slightly more complicated because we want to stop -// once we have enough digits. That is, once the digits inside the buffer -// represent 'w' we can stop. Everything inside the interval low - high -// represents w. However we have to pay attention to low, high and w's -// imprecision. -bool DigitGen(DiyFp low, - DiyFp w, - DiyFp high, - Vector buffer, - int* length, - int* kappa) { - ASSERT(low.e() == w.e() && w.e() == high.e()); - ASSERT(low.f() + 1 <= high.f() - 1); - ASSERT(minimal_target_exponent <= w.e() && w.e() <= maximal_target_exponent); - // low, w and high are imprecise, but by less than one ulp (unit in the last - // place). - // If we remove (resp. add) 1 ulp from low (resp. high) we are certain that - // the new numbers are outside of the interval we want the final - // representation to lie in. - // Inversely adding (resp. removing) 1 ulp from low (resp. high) would yield - // numbers that are certain to lie in the interval. We will use this fact - // later on. - // We will now start by generating the digits within the uncertain - // interval. Later we will weed out representations that lie outside the safe - // interval and thus _might_ lie outside the correct interval. - uint64_t unit = 1; - DiyFp too_low = DiyFp(low.f() - unit, low.e()); - DiyFp too_high = DiyFp(high.f() + unit, high.e()); - // too_low and too_high are guaranteed to lie outside the interval we want the - // generated number in. - DiyFp unsafe_interval = DiyFp::Minus(too_high, too_low); - // We now cut the input number into two parts: the integral digits and the - // fractionals. We will not write any decimal separator though, but adapt - // kappa instead. - // Reminder: we are currently computing the digits (stored inside the buffer) - // such that: too_low < buffer * 10^kappa < too_high - // We use too_high for the digit_generation and stop as soon as possible. - // If we stop early we effectively round down. - DiyFp one = DiyFp(static_cast(1) << -w.e(), w.e()); - // Division by one is a shift. - uint32_t integrals = static_cast(too_high.f() >> -one.e()); - // Modulo by one is an and. - uint64_t fractionals = too_high.f() & (one.f() - 1); - uint32_t divider; - int divider_exponent; - BiggestPowerTen(integrals, DiyFp::kSignificandSize - (-one.e()), - ÷r, ÷r_exponent); - *kappa = divider_exponent + 1; - *length = 0; - // Loop invariant: buffer = too_high / 10^kappa (integer division) - // The invariant holds for the first iteration: kappa has been initialized - // with the divider exponent + 1. And the divider is the biggest power of ten - // that is smaller than integrals. - while (*kappa > 0) { - int digit = integrals / divider; - buffer[*length] = '0' + digit; - (*length)++; - integrals %= divider; - (*kappa)--; - // Note that kappa now equals the exponent of the divider and that the - // invariant thus holds again. - uint64_t rest = - (static_cast(integrals) << -one.e()) + fractionals; - // Invariant: too_high = buffer * 10^kappa + DiyFp(rest, one.e()) - // Reminder: unsafe_interval.e() == one.e() - if (rest < unsafe_interval.f()) { - // Rounding down (by not emitting the remaining digits) yields a number - // that lies within the unsafe interval. - return RoundWeed(buffer, *length, DiyFp::Minus(too_high, w).f(), - unsafe_interval.f(), rest, - static_cast(divider) << -one.e(), unit); - } - divider /= 10; - } - - // The integrals have been generated. We are at the point of the decimal - // separator. In the following loop we simply multiply the remaining digits by - // 10 and divide by one. We just need to pay attention to multiply associated - // data (like the interval or 'unit'), too. - // Instead of multiplying by 10 we multiply by 5 (cheaper operation) and - // increase its (imaginary) exponent. At the same time we decrease the - // divider's (one's) exponent and shift its significand. - // Basically, if fractionals was a DiyFp (with fractionals.e == one.e): - // fractionals.f *= 10; - // fractionals.f >>= 1; fractionals.e++; // value remains unchanged. - // one.f >>= 1; one.e++; // value remains unchanged. - // and we have again fractionals.e == one.e which allows us to divide - // fractionals.f() by one.f() - // We simply combine the *= 10 and the >>= 1. - while (true) { - fractionals *= 5; - unit *= 5; - unsafe_interval.set_f(unsafe_interval.f() * 5); - unsafe_interval.set_e(unsafe_interval.e() + 1); // Will be optimized out. - one.set_f(one.f() >> 1); - one.set_e(one.e() + 1); - // Integer division by one. - int digit = static_cast(fractionals >> -one.e()); - buffer[*length] = '0' + digit; - (*length)++; - fractionals &= one.f() - 1; // Modulo by one. - (*kappa)--; - if (fractionals < unsafe_interval.f()) { - return RoundWeed(buffer, *length, DiyFp::Minus(too_high, w).f() * unit, - unsafe_interval.f(), fractionals, one.f(), unit); - } - } -} - - -// Provides a decimal representation of v. -// Returns true if it succeeds, otherwise the result cannot be trusted. -// There will be *length digits inside the buffer (not null-terminated). -// If the function returns true then -// v == (double) (buffer * 10^decimal_exponent). -// The digits in the buffer are the shortest representation possible: no -// 0.09999999999999999 instead of 0.1. The shorter representation will even be -// chosen even if the longer one would be closer to v. -// The last digit will be closest to the actual v. That is, even if several -// digits might correctly yield 'v' when read again, the closest will be -// computed. -bool grisu3(double v, Vector buffer, int* length, int* decimal_exponent) { - DiyFp w = Double(v).AsNormalizedDiyFp(); - // boundary_minus and boundary_plus are the boundaries between v and its - // closest floating-point neighbors. Any number strictly between - // boundary_minus and boundary_plus will round to v when convert to a double. - // Grisu3 will never output representations that lie exactly on a boundary. - DiyFp boundary_minus, boundary_plus; - Double(v).NormalizedBoundaries(&boundary_minus, &boundary_plus); - ASSERT(boundary_plus.e() == w.e()); - DiyFp ten_mk; // Cached power of ten: 10^-k - int mk; // -k - GetCachedPower(w.e() + DiyFp::kSignificandSize, minimal_target_exponent, - maximal_target_exponent, &mk, &ten_mk); - ASSERT(minimal_target_exponent <= w.e() + ten_mk.e() + - DiyFp::kSignificandSize && - maximal_target_exponent >= w.e() + ten_mk.e() + - DiyFp::kSignificandSize); - // Note that ten_mk is only an approximation of 10^-k. A DiyFp only contains a - // 64 bit significand and ten_mk is thus only precise up to 64 bits. - - // The DiyFp::Times procedure rounds its result, and ten_mk is approximated - // too. The variable scaled_w (as well as scaled_boundary_minus/plus) are now - // off by a small amount. - // In fact: scaled_w - w*10^k < 1ulp (unit in the last place) of scaled_w. - // In other words: let f = scaled_w.f() and e = scaled_w.e(), then - // (f-1) * 2^e < w*10^k < (f+1) * 2^e - DiyFp scaled_w = DiyFp::Times(w, ten_mk); - ASSERT(scaled_w.e() == - boundary_plus.e() + ten_mk.e() + DiyFp::kSignificandSize); - // In theory it would be possible to avoid some recomputations by computing - // the difference between w and boundary_minus/plus (a power of 2) and to - // compute scaled_boundary_minus/plus by subtracting/adding from - // scaled_w. However the code becomes much less readable and the speed - // enhancements are not terriffic. - DiyFp scaled_boundary_minus = DiyFp::Times(boundary_minus, ten_mk); - DiyFp scaled_boundary_plus = DiyFp::Times(boundary_plus, ten_mk); - - // DigitGen will generate the digits of scaled_w. Therefore we have - // v == (double) (scaled_w * 10^-mk). - // Set decimal_exponent == -mk and pass it to DigitGen. If scaled_w is not an - // integer than it will be updated. For instance if scaled_w == 1.23 then - // the buffer will be filled with "123" und the decimal_exponent will be - // decreased by 2. - int kappa; - bool result = DigitGen(scaled_boundary_minus, scaled_w, scaled_boundary_plus, - buffer, length, &kappa); - *decimal_exponent = -mk + kappa; - return result; -} - - -bool FastDtoa(double v, - Vector buffer, - int* length, - int* point) { - ASSERT(v > 0); - ASSERT(!Double(v).IsSpecial()); - - int decimal_exponent; - bool result = grisu3(v, buffer, length, &decimal_exponent); - *point = *length + decimal_exponent; - buffer[*length] = '\0'; - return result; -} - -} } // namespace v8::internal diff --git a/js/src/v8-dtoa/fast-dtoa.h b/js/src/v8-dtoa/fast-dtoa.h deleted file mode 100644 index 4403a7502926..000000000000 --- a/js/src/v8-dtoa/fast-dtoa.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2010 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef V8_FAST_DTOA_H_ -#define V8_FAST_DTOA_H_ - -namespace v8 { -namespace internal { - -// FastDtoa will produce at most kFastDtoaMaximalLength digits. This does not -// include the terminating '\0' character. -static const int kFastDtoaMaximalLength = 17; - -// Provides a decimal representation of v. -// v must be a strictly positive finite double. -// Returns true if it succeeds, otherwise the result can not be trusted. -// There will be *length digits inside the buffer followed by a null terminator. -// If the function returns true then -// v == (double) (buffer * 10^(point - length)). -// The digits in the buffer are the shortest representation possible: no -// 0.099999999999 instead of 0.1. -// The last digit will be closest to the actual v. That is, even if several -// digits might correctly yield 'v' when read again, the buffer will contain the -// one closest to v. -// The variable 'sign' will be '0' if the given number is positive, and '1' -// otherwise. -bool FastDtoa(double d, - Vector buffer, - int* length, - int* point); - -} } // namespace v8::internal - -#endif // V8_FAST_DTOA_H_ diff --git a/js/src/v8-dtoa/globals.h b/js/src/v8-dtoa/globals.h deleted file mode 100644 index 5f5ba9ee3e9c..000000000000 --- a/js/src/v8-dtoa/globals.h +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2006-2009 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef V8_GLOBALS_H_ -#define V8_GLOBALS_H_ - -namespace v8 { -namespace internal { - - -// The following macro works on both 32 and 64-bit platforms. -// Usage: instead of writing 0x1234567890123456 -// write V8_2PART_UINT64_C(0x12345678,90123456); -#define V8_2PART_UINT64_C(a, b) (((static_cast(a) << 32) + 0x##b##u)) - -// ----------------------------------------------------------------------------- -// Constants - -const int kCharSize = sizeof(char); // NOLINT - - -// ----------------------------------------------------------------------------- -// Macros - - -// A macro to disallow the evil copy constructor and operator= functions -// This should be used in the private: declarations for a class -#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ - TypeName(const TypeName&); \ - void operator=(const TypeName&) - - -// A macro to disallow all the implicit constructors, namely the -// default constructor, copy constructor and operator= functions. -// -// This should be used in the private: declarations for a class -// that wants to prevent anyone from instantiating it. This is -// especially useful for classes containing only static methods. -#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ - TypeName(); \ - DISALLOW_COPY_AND_ASSIGN(TypeName) - -} } // namespace v8::internal - -#endif // V8_GLOBALS_H_ diff --git a/js/src/v8-dtoa/include-v8.h b/js/src/v8-dtoa/include-v8.h deleted file mode 100644 index e44d5c8ead4f..000000000000 --- a/js/src/v8-dtoa/include-v8.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2007-2009 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef V8_H_ -#define V8_H_ - -// MOZ: this file was called ../include/v8.h (that's relative to the V8's src/ -// directory). It was renamed so that all V8 files could be put in one -// directory within SpiderMonkey. All #includes were modified accordingly. - -#include - -#ifdef _WIN32 -// When compiling on MinGW stdint.h is available. -#ifdef __MINGW32__ -#include -#else // __MINGW32__ -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef short int16_t; // NOLINT -typedef unsigned short uint16_t; // NOLINT -typedef int int32_t; -typedef unsigned int uint32_t; -typedef __int64 int64_t; -typedef unsigned __int64 uint64_t; -// intptr_t and friends are defined in crtdefs.h through stdio.h. -#endif // __MINGW32__ - -#else // _WIN32 - -#include - -#endif // _WIN32 - -#endif // V8_H_ diff --git a/js/src/v8-dtoa/platform.cc b/js/src/v8-dtoa/platform.cc deleted file mode 100644 index 5fd4ce85b658..000000000000 --- a/js/src/v8-dtoa/platform.cc +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright 2006-2008 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// MOZ: This file is a merge of the relevant parts of all the platform-*.cc -// files in v8; the amount of code remaining was small enough that putting -// everything in a single file was easier, particularly because it means we -// can always compile this one file on every platform. - -#include -#include -#include - -#include "v8.h" - -namespace v8 { -namespace internal { - -double ceiling(double x) { -#if defined(__APPLE__) - // Correct Mac OS X Leopard 'ceil' behavior. - // - // MOZ: This appears to be fixed in Mac OS X 10.5.8. - // - // MOZ: This fix is apprently also required for FreeBSD and OpenBSD, if we - // have to worry about them. - if (-1.0 < x && x < 0.0) { - return -0.0; - } else { - return ceil(x); - } -#else - return ceil(x); -#endif -} - - -// MOZ: These exit behaviours were copied from SpiderMonkey's JS_Assert() -// function. -void OS::Abort() { -#if defined(WIN32) - /* - * We used to call DebugBreak() on Windows, but amazingly, it causes - * the MSVS 2010 debugger not to be able to recover a call stack. - */ - *((volatile int *) NULL) = 0; - exit(3); -#elif defined(__APPLE__) - /* - * On Mac OS X, Breakpad ignores signals. Only real Mach exceptions are - * trapped. - */ - *((volatile int *) NULL) = 0; /* To continue from here in GDB: "return" then "continue". */ - raise(SIGABRT); /* In case above statement gets nixed by the optimizer. */ -#else - raise(SIGABRT); /* To continue from here in GDB: "signal 0". */ -#endif -} - -} } // namespace v8::internal - -// Extra POSIX/ANSI routines for Win32 when when using Visual Studio C++. Please -// refer to The Open Group Base Specification for specification of the correct -// semantics for these functions. -// (http://www.opengroup.org/onlinepubs/000095399/) -#ifdef _MSC_VER - -#include - -// Classify floating point number - usually defined in math.h -int fpclassify(double x) { - // Use the MS-specific _fpclass() for classification. - int flags = _fpclass(x); - - // Determine class. We cannot use a switch statement because - // the _FPCLASS_ constants are defined as flags. - if (flags & (_FPCLASS_PN | _FPCLASS_NN)) return FP_NORMAL; - if (flags & (_FPCLASS_PZ | _FPCLASS_NZ)) return FP_ZERO; - if (flags & (_FPCLASS_PD | _FPCLASS_ND)) return FP_SUBNORMAL; - if (flags & (_FPCLASS_PINF | _FPCLASS_NINF)) return FP_INFINITE; - - // All cases should be covered by the code above. - ASSERT(flags & (_FPCLASS_SNAN | _FPCLASS_QNAN)); - return FP_NAN; -} - - -#endif // _MSC_VER - -#ifdef SOLARIS - -#include - -// Classify floating point number -int fpclassify(double x) { - - fpclass_t rv = fpclass(x); - - switch (rv) { - case FP_SNAN: - case FP_QNAN: return FP_NAN; - case FP_NINF: - case FP_PINF: return FP_INFINITE; - case FP_NDENORM: - case FP_PDENORM: return FP_SUBNORMAL; - case FP_NZERO: - case FP_PZERO: return FP_ZERO; - default: - ASSERT(rv == FP_NNORM || rv == FP_PNORM); - return FP_NORMAL; - } - -} -#endif // SOLARIS diff --git a/js/src/v8-dtoa/platform.h b/js/src/v8-dtoa/platform.h deleted file mode 100644 index 047f75a8c6c0..000000000000 --- a/js/src/v8-dtoa/platform.h +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2006-2008 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This module contains the platform-specific code. This make the rest of the -// code less dependent on operating system, compilers and runtime libraries. -// This module does specifically not deal with differences between different -// processor architecture. -// The platform classes have the same definition for all platforms. The -// implementation for a particular platform is put in platform_.cc. -// The build system then uses the implementation for the target platform. -// -// This design has been chosen because it is simple and fast. Alternatively, -// the platform dependent classes could have been implemented using abstract -// superclasses with virtual methods and having specializations for each -// platform. This design was rejected because it was more complicated and -// slower. It would require factory methods for selecting the right -// implementation and the overhead of virtual methods for performance -// sensitive like mutex locking/unlocking. - -#ifndef V8_PLATFORM_H_ -#define V8_PLATFORM_H_ - -// Windows specific stuff. -#ifdef WIN32 - -// Microsoft Visual C++ specific stuff. -#ifdef _MSC_VER - -enum { - FP_NAN, - FP_INFINITE, - FP_ZERO, - FP_SUBNORMAL, - FP_NORMAL -}; - -int fpclassify(double x); - -int strncasecmp(const char* s1, const char* s2, int n); - -#endif // _MSC_VER - -#endif // WIN32 - -#ifdef SOLARIS -int fpclassify(double x); -#endif // SOLARIS - -// GCC specific stuff -#ifdef __GNUC__ - -// Needed for va_list on at least MinGW and Android. -#include - -#define __GNUC_VERSION__ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) - -#endif // __GNUC__ - -namespace v8 { -namespace internal { - -double ceiling(double x); - -// ---------------------------------------------------------------------------- -// OS -// -// This class has static methods for the different platform specific -// functions. Add methods here to cope with differences between the -// supported platforms. - -class OS { - public: - // Abort the current process. - static void Abort(); -}; - -} } // namespace v8::internal - -#endif // V8_PLATFORM_H_ diff --git a/js/src/v8-dtoa/powers-ten.h b/js/src/v8-dtoa/powers-ten.h deleted file mode 100644 index 93d92d917c8c..000000000000 --- a/js/src/v8-dtoa/powers-ten.h +++ /dev/null @@ -1,2461 +0,0 @@ -// Copyright 2010 the V8 project authors. All rights reserved. -// ------------ GENERATED FILE ---------------- -// command used: -// tools/generate-ten-powers --from -308 --to 342 --mantissa-size 64 --round round -o src/powers-ten.h // NOLINT - -// This file is intended to be included inside another .h or .cc files -// with the following defines set: -// GRISU_CACHE_STRUCT: should expand to the name of a struct that will -// hold the cached powers of ten. Each entry will hold a 64-bit -// significand, a 16-bit signed binary exponent, and a 16-bit -// signed decimal exponent. Each entry will be constructed as follows: -// { significand, binary_exponent, decimal_exponent }. -// GRISU_CACHE_NAME(i): generates the name for the different caches. -// The parameter i will be a number in the range 1-20. A cache will -// hold every i'th element of a full cache. GRISU_CACHE_NAME(1) will -// thus hold all elements. The higher i the fewer elements it has. -// Ideally the user should only reference one cache and let the -// compiler remove the unused ones. -// GRISU_CACHE_MAX_DISTANCE(i): generates the name for the maximum -// binary exponent distance between all elements of a given cache. -// GRISU_CACHE_OFFSET: is used as variable name for the decimal -// exponent offset. It is equal to -cache[0].decimal_exponent. -// GRISU_UINT64_C: used to construct 64-bit values in a platform -// independent way. In order to encode 0x123456789ABCDEF0 the macro -// will be invoked as follows: GRISU_UINT64_C(0x12345678,9ABCDEF0). - - -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(1)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0x8fd0c162, 06306bac), -1083, -307}, - {GRISU_UINT64_C(0xb3c4f1ba, 87bc8697), -1080, -306}, - {GRISU_UINT64_C(0xe0b62e29, 29aba83c), -1077, -305}, - {GRISU_UINT64_C(0x8c71dcd9, ba0b4926), -1073, -304}, - {GRISU_UINT64_C(0xaf8e5410, 288e1b6f), -1070, -303}, - {GRISU_UINT64_C(0xdb71e914, 32b1a24b), -1067, -302}, - {GRISU_UINT64_C(0x892731ac, 9faf056f), -1063, -301}, - {GRISU_UINT64_C(0xab70fe17, c79ac6ca), -1060, -300}, - {GRISU_UINT64_C(0xd64d3d9d, b981787d), -1057, -299}, - {GRISU_UINT64_C(0x85f04682, 93f0eb4e), -1053, -298}, - {GRISU_UINT64_C(0xa76c5823, 38ed2622), -1050, -297}, - {GRISU_UINT64_C(0xd1476e2c, 07286faa), -1047, -296}, - {GRISU_UINT64_C(0x82cca4db, 847945ca), -1043, -295}, - {GRISU_UINT64_C(0xa37fce12, 6597973d), -1040, -294}, - {GRISU_UINT64_C(0xcc5fc196, fefd7d0c), -1037, -293}, - {GRISU_UINT64_C(0xff77b1fc, bebcdc4f), -1034, -292}, - {GRISU_UINT64_C(0x9faacf3d, f73609b1), -1030, -291}, - {GRISU_UINT64_C(0xc795830d, 75038c1e), -1027, -290}, - {GRISU_UINT64_C(0xf97ae3d0, d2446f25), -1024, -289}, - {GRISU_UINT64_C(0x9becce62, 836ac577), -1020, -288}, - {GRISU_UINT64_C(0xc2e801fb, 244576d5), -1017, -287}, - {GRISU_UINT64_C(0xf3a20279, ed56d48a), -1014, -286}, - {GRISU_UINT64_C(0x9845418c, 345644d7), -1010, -285}, - {GRISU_UINT64_C(0xbe5691ef, 416bd60c), -1007, -284}, - {GRISU_UINT64_C(0xedec366b, 11c6cb8f), -1004, -283}, - {GRISU_UINT64_C(0x94b3a202, eb1c3f39), -1000, -282}, - {GRISU_UINT64_C(0xb9e08a83, a5e34f08), -997, -281}, - {GRISU_UINT64_C(0xe858ad24, 8f5c22ca), -994, -280}, - {GRISU_UINT64_C(0x91376c36, d99995be), -990, -279}, - {GRISU_UINT64_C(0xb5854744, 8ffffb2e), -987, -278}, - {GRISU_UINT64_C(0xe2e69915, b3fff9f9), -984, -277}, - {GRISU_UINT64_C(0x8dd01fad, 907ffc3c), -980, -276}, - {GRISU_UINT64_C(0xb1442798, f49ffb4b), -977, -275}, - {GRISU_UINT64_C(0xdd95317f, 31c7fa1d), -974, -274}, - {GRISU_UINT64_C(0x8a7d3eef, 7f1cfc52), -970, -273}, - {GRISU_UINT64_C(0xad1c8eab, 5ee43b67), -967, -272}, - {GRISU_UINT64_C(0xd863b256, 369d4a41), -964, -271}, - {GRISU_UINT64_C(0x873e4f75, e2224e68), -960, -270}, - {GRISU_UINT64_C(0xa90de353, 5aaae202), -957, -269}, - {GRISU_UINT64_C(0xd3515c28, 31559a83), -954, -268}, - {GRISU_UINT64_C(0x8412d999, 1ed58092), -950, -267}, - {GRISU_UINT64_C(0xa5178fff, 668ae0b6), -947, -266}, - {GRISU_UINT64_C(0xce5d73ff, 402d98e4), -944, -265}, - {GRISU_UINT64_C(0x80fa687f, 881c7f8e), -940, -264}, - {GRISU_UINT64_C(0xa139029f, 6a239f72), -937, -263}, - {GRISU_UINT64_C(0xc9874347, 44ac874f), -934, -262}, - {GRISU_UINT64_C(0xfbe91419, 15d7a922), -931, -261}, - {GRISU_UINT64_C(0x9d71ac8f, ada6c9b5), -927, -260}, - {GRISU_UINT64_C(0xc4ce17b3, 99107c23), -924, -259}, - {GRISU_UINT64_C(0xf6019da0, 7f549b2b), -921, -258}, - {GRISU_UINT64_C(0x99c10284, 4f94e0fb), -917, -257}, - {GRISU_UINT64_C(0xc0314325, 637a193a), -914, -256}, - {GRISU_UINT64_C(0xf03d93ee, bc589f88), -911, -255}, - {GRISU_UINT64_C(0x96267c75, 35b763b5), -907, -254}, - {GRISU_UINT64_C(0xbbb01b92, 83253ca3), -904, -253}, - {GRISU_UINT64_C(0xea9c2277, 23ee8bcb), -901, -252}, - {GRISU_UINT64_C(0x92a1958a, 7675175f), -897, -251}, - {GRISU_UINT64_C(0xb749faed, 14125d37), -894, -250}, - {GRISU_UINT64_C(0xe51c79a8, 5916f485), -891, -249}, - {GRISU_UINT64_C(0x8f31cc09, 37ae58d3), -887, -248}, - {GRISU_UINT64_C(0xb2fe3f0b, 8599ef08), -884, -247}, - {GRISU_UINT64_C(0xdfbdcece, 67006ac9), -881, -246}, - {GRISU_UINT64_C(0x8bd6a141, 006042be), -877, -245}, - {GRISU_UINT64_C(0xaecc4991, 4078536d), -874, -244}, - {GRISU_UINT64_C(0xda7f5bf5, 90966849), -871, -243}, - {GRISU_UINT64_C(0x888f9979, 7a5e012d), -867, -242}, - {GRISU_UINT64_C(0xaab37fd7, d8f58179), -864, -241}, - {GRISU_UINT64_C(0xd5605fcd, cf32e1d7), -861, -240}, - {GRISU_UINT64_C(0x855c3be0, a17fcd26), -857, -239}, - {GRISU_UINT64_C(0xa6b34ad8, c9dfc070), -854, -238}, - {GRISU_UINT64_C(0xd0601d8e, fc57b08c), -851, -237}, - {GRISU_UINT64_C(0x823c1279, 5db6ce57), -847, -236}, - {GRISU_UINT64_C(0xa2cb1717, b52481ed), -844, -235}, - {GRISU_UINT64_C(0xcb7ddcdd, a26da269), -841, -234}, - {GRISU_UINT64_C(0xfe5d5415, 0b090b03), -838, -233}, - {GRISU_UINT64_C(0x9efa548d, 26e5a6e2), -834, -232}, - {GRISU_UINT64_C(0xc6b8e9b0, 709f109a), -831, -231}, - {GRISU_UINT64_C(0xf867241c, 8cc6d4c1), -828, -230}, - {GRISU_UINT64_C(0x9b407691, d7fc44f8), -824, -229}, - {GRISU_UINT64_C(0xc2109436, 4dfb5637), -821, -228}, - {GRISU_UINT64_C(0xf294b943, e17a2bc4), -818, -227}, - {GRISU_UINT64_C(0x979cf3ca, 6cec5b5b), -814, -226}, - {GRISU_UINT64_C(0xbd8430bd, 08277231), -811, -225}, - {GRISU_UINT64_C(0xece53cec, 4a314ebe), -808, -224}, - {GRISU_UINT64_C(0x940f4613, ae5ed137), -804, -223}, - {GRISU_UINT64_C(0xb9131798, 99f68584), -801, -222}, - {GRISU_UINT64_C(0xe757dd7e, c07426e5), -798, -221}, - {GRISU_UINT64_C(0x9096ea6f, 3848984f), -794, -220}, - {GRISU_UINT64_C(0xb4bca50b, 065abe63), -791, -219}, - {GRISU_UINT64_C(0xe1ebce4d, c7f16dfc), -788, -218}, - {GRISU_UINT64_C(0x8d3360f0, 9cf6e4bd), -784, -217}, - {GRISU_UINT64_C(0xb080392c, c4349ded), -781, -216}, - {GRISU_UINT64_C(0xdca04777, f541c568), -778, -215}, - {GRISU_UINT64_C(0x89e42caa, f9491b61), -774, -214}, - {GRISU_UINT64_C(0xac5d37d5, b79b6239), -771, -213}, - {GRISU_UINT64_C(0xd77485cb, 25823ac7), -768, -212}, - {GRISU_UINT64_C(0x86a8d39e, f77164bd), -764, -211}, - {GRISU_UINT64_C(0xa8530886, b54dbdec), -761, -210}, - {GRISU_UINT64_C(0xd267caa8, 62a12d67), -758, -209}, - {GRISU_UINT64_C(0x8380dea9, 3da4bc60), -754, -208}, - {GRISU_UINT64_C(0xa4611653, 8d0deb78), -751, -207}, - {GRISU_UINT64_C(0xcd795be8, 70516656), -748, -206}, - {GRISU_UINT64_C(0x806bd971, 4632dff6), -744, -205}, - {GRISU_UINT64_C(0xa086cfcd, 97bf97f4), -741, -204}, - {GRISU_UINT64_C(0xc8a883c0, fdaf7df0), -738, -203}, - {GRISU_UINT64_C(0xfad2a4b1, 3d1b5d6c), -735, -202}, - {GRISU_UINT64_C(0x9cc3a6ee, c6311a64), -731, -201}, - {GRISU_UINT64_C(0xc3f490aa, 77bd60fd), -728, -200}, - {GRISU_UINT64_C(0xf4f1b4d5, 15acb93c), -725, -199}, - {GRISU_UINT64_C(0x99171105, 2d8bf3c5), -721, -198}, - {GRISU_UINT64_C(0xbf5cd546, 78eef0b7), -718, -197}, - {GRISU_UINT64_C(0xef340a98, 172aace5), -715, -196}, - {GRISU_UINT64_C(0x9580869f, 0e7aac0f), -711, -195}, - {GRISU_UINT64_C(0xbae0a846, d2195713), -708, -194}, - {GRISU_UINT64_C(0xe998d258, 869facd7), -705, -193}, - {GRISU_UINT64_C(0x91ff8377, 5423cc06), -701, -192}, - {GRISU_UINT64_C(0xb67f6455, 292cbf08), -698, -191}, - {GRISU_UINT64_C(0xe41f3d6a, 7377eeca), -695, -190}, - {GRISU_UINT64_C(0x8e938662, 882af53e), -691, -189}, - {GRISU_UINT64_C(0xb23867fb, 2a35b28e), -688, -188}, - {GRISU_UINT64_C(0xdec681f9, f4c31f31), -685, -187}, - {GRISU_UINT64_C(0x8b3c113c, 38f9f37f), -681, -186}, - {GRISU_UINT64_C(0xae0b158b, 4738705f), -678, -185}, - {GRISU_UINT64_C(0xd98ddaee, 19068c76), -675, -184}, - {GRISU_UINT64_C(0x87f8a8d4, cfa417ca), -671, -183}, - {GRISU_UINT64_C(0xa9f6d30a, 038d1dbc), -668, -182}, - {GRISU_UINT64_C(0xd47487cc, 8470652b), -665, -181}, - {GRISU_UINT64_C(0x84c8d4df, d2c63f3b), -661, -180}, - {GRISU_UINT64_C(0xa5fb0a17, c777cf0a), -658, -179}, - {GRISU_UINT64_C(0xcf79cc9d, b955c2cc), -655, -178}, - {GRISU_UINT64_C(0x81ac1fe2, 93d599c0), -651, -177}, - {GRISU_UINT64_C(0xa21727db, 38cb0030), -648, -176}, - {GRISU_UINT64_C(0xca9cf1d2, 06fdc03c), -645, -175}, - {GRISU_UINT64_C(0xfd442e46, 88bd304b), -642, -174}, - {GRISU_UINT64_C(0x9e4a9cec, 15763e2f), -638, -173}, - {GRISU_UINT64_C(0xc5dd4427, 1ad3cdba), -635, -172}, - {GRISU_UINT64_C(0xf7549530, e188c129), -632, -171}, - {GRISU_UINT64_C(0x9a94dd3e, 8cf578ba), -628, -170}, - {GRISU_UINT64_C(0xc13a148e, 3032d6e8), -625, -169}, - {GRISU_UINT64_C(0xf18899b1, bc3f8ca2), -622, -168}, - {GRISU_UINT64_C(0x96f5600f, 15a7b7e5), -618, -167}, - {GRISU_UINT64_C(0xbcb2b812, db11a5de), -615, -166}, - {GRISU_UINT64_C(0xebdf6617, 91d60f56), -612, -165}, - {GRISU_UINT64_C(0x936b9fce, bb25c996), -608, -164}, - {GRISU_UINT64_C(0xb84687c2, 69ef3bfb), -605, -163}, - {GRISU_UINT64_C(0xe65829b3, 046b0afa), -602, -162}, - {GRISU_UINT64_C(0x8ff71a0f, e2c2e6dc), -598, -161}, - {GRISU_UINT64_C(0xb3f4e093, db73a093), -595, -160}, - {GRISU_UINT64_C(0xe0f218b8, d25088b8), -592, -159}, - {GRISU_UINT64_C(0x8c974f73, 83725573), -588, -158}, - {GRISU_UINT64_C(0xafbd2350, 644eead0), -585, -157}, - {GRISU_UINT64_C(0xdbac6c24, 7d62a584), -582, -156}, - {GRISU_UINT64_C(0x894bc396, ce5da772), -578, -155}, - {GRISU_UINT64_C(0xab9eb47c, 81f5114f), -575, -154}, - {GRISU_UINT64_C(0xd686619b, a27255a3), -572, -153}, - {GRISU_UINT64_C(0x8613fd01, 45877586), -568, -152}, - {GRISU_UINT64_C(0xa798fc41, 96e952e7), -565, -151}, - {GRISU_UINT64_C(0xd17f3b51, fca3a7a1), -562, -150}, - {GRISU_UINT64_C(0x82ef8513, 3de648c5), -558, -149}, - {GRISU_UINT64_C(0xa3ab6658, 0d5fdaf6), -555, -148}, - {GRISU_UINT64_C(0xcc963fee, 10b7d1b3), -552, -147}, - {GRISU_UINT64_C(0xffbbcfe9, 94e5c620), -549, -146}, - {GRISU_UINT64_C(0x9fd561f1, fd0f9bd4), -545, -145}, - {GRISU_UINT64_C(0xc7caba6e, 7c5382c9), -542, -144}, - {GRISU_UINT64_C(0xf9bd690a, 1b68637b), -539, -143}, - {GRISU_UINT64_C(0x9c1661a6, 51213e2d), -535, -142}, - {GRISU_UINT64_C(0xc31bfa0f, e5698db8), -532, -141}, - {GRISU_UINT64_C(0xf3e2f893, dec3f126), -529, -140}, - {GRISU_UINT64_C(0x986ddb5c, 6b3a76b8), -525, -139}, - {GRISU_UINT64_C(0xbe895233, 86091466), -522, -138}, - {GRISU_UINT64_C(0xee2ba6c0, 678b597f), -519, -137}, - {GRISU_UINT64_C(0x94db4838, 40b717f0), -515, -136}, - {GRISU_UINT64_C(0xba121a46, 50e4ddec), -512, -135}, - {GRISU_UINT64_C(0xe896a0d7, e51e1566), -509, -134}, - {GRISU_UINT64_C(0x915e2486, ef32cd60), -505, -133}, - {GRISU_UINT64_C(0xb5b5ada8, aaff80b8), -502, -132}, - {GRISU_UINT64_C(0xe3231912, d5bf60e6), -499, -131}, - {GRISU_UINT64_C(0x8df5efab, c5979c90), -495, -130}, - {GRISU_UINT64_C(0xb1736b96, b6fd83b4), -492, -129}, - {GRISU_UINT64_C(0xddd0467c, 64bce4a1), -489, -128}, - {GRISU_UINT64_C(0x8aa22c0d, bef60ee4), -485, -127}, - {GRISU_UINT64_C(0xad4ab711, 2eb3929e), -482, -126}, - {GRISU_UINT64_C(0xd89d64d5, 7a607745), -479, -125}, - {GRISU_UINT64_C(0x87625f05, 6c7c4a8b), -475, -124}, - {GRISU_UINT64_C(0xa93af6c6, c79b5d2e), -472, -123}, - {GRISU_UINT64_C(0xd389b478, 79823479), -469, -122}, - {GRISU_UINT64_C(0x843610cb, 4bf160cc), -465, -121}, - {GRISU_UINT64_C(0xa54394fe, 1eedb8ff), -462, -120}, - {GRISU_UINT64_C(0xce947a3d, a6a9273e), -459, -119}, - {GRISU_UINT64_C(0x811ccc66, 8829b887), -455, -118}, - {GRISU_UINT64_C(0xa163ff80, 2a3426a9), -452, -117}, - {GRISU_UINT64_C(0xc9bcff60, 34c13053), -449, -116}, - {GRISU_UINT64_C(0xfc2c3f38, 41f17c68), -446, -115}, - {GRISU_UINT64_C(0x9d9ba783, 2936edc1), -442, -114}, - {GRISU_UINT64_C(0xc5029163, f384a931), -439, -113}, - {GRISU_UINT64_C(0xf64335bc, f065d37d), -436, -112}, - {GRISU_UINT64_C(0x99ea0196, 163fa42e), -432, -111}, - {GRISU_UINT64_C(0xc06481fb, 9bcf8d3a), -429, -110}, - {GRISU_UINT64_C(0xf07da27a, 82c37088), -426, -109}, - {GRISU_UINT64_C(0x964e858c, 91ba2655), -422, -108}, - {GRISU_UINT64_C(0xbbe226ef, b628afeb), -419, -107}, - {GRISU_UINT64_C(0xeadab0ab, a3b2dbe5), -416, -106}, - {GRISU_UINT64_C(0x92c8ae6b, 464fc96f), -412, -105}, - {GRISU_UINT64_C(0xb77ada06, 17e3bbcb), -409, -104}, - {GRISU_UINT64_C(0xe5599087, 9ddcaabe), -406, -103}, - {GRISU_UINT64_C(0x8f57fa54, c2a9eab7), -402, -102}, - {GRISU_UINT64_C(0xb32df8e9, f3546564), -399, -101}, - {GRISU_UINT64_C(0xdff97724, 70297ebd), -396, -100}, - {GRISU_UINT64_C(0x8bfbea76, c619ef36), -392, -99}, - {GRISU_UINT64_C(0xaefae514, 77a06b04), -389, -98}, - {GRISU_UINT64_C(0xdab99e59, 958885c5), -386, -97}, - {GRISU_UINT64_C(0x88b402f7, fd75539b), -382, -96}, - {GRISU_UINT64_C(0xaae103b5, fcd2a882), -379, -95}, - {GRISU_UINT64_C(0xd59944a3, 7c0752a2), -376, -94}, - {GRISU_UINT64_C(0x857fcae6, 2d8493a5), -372, -93}, - {GRISU_UINT64_C(0xa6dfbd9f, b8e5b88f), -369, -92}, - {GRISU_UINT64_C(0xd097ad07, a71f26b2), -366, -91}, - {GRISU_UINT64_C(0x825ecc24, c8737830), -362, -90}, - {GRISU_UINT64_C(0xa2f67f2d, fa90563b), -359, -89}, - {GRISU_UINT64_C(0xcbb41ef9, 79346bca), -356, -88}, - {GRISU_UINT64_C(0xfea126b7, d78186bd), -353, -87}, - {GRISU_UINT64_C(0x9f24b832, e6b0f436), -349, -86}, - {GRISU_UINT64_C(0xc6ede63f, a05d3144), -346, -85}, - {GRISU_UINT64_C(0xf8a95fcf, 88747d94), -343, -84}, - {GRISU_UINT64_C(0x9b69dbe1, b548ce7d), -339, -83}, - {GRISU_UINT64_C(0xc24452da, 229b021c), -336, -82}, - {GRISU_UINT64_C(0xf2d56790, ab41c2a3), -333, -81}, - {GRISU_UINT64_C(0x97c560ba, 6b0919a6), -329, -80}, - {GRISU_UINT64_C(0xbdb6b8e9, 05cb600f), -326, -79}, - {GRISU_UINT64_C(0xed246723, 473e3813), -323, -78}, - {GRISU_UINT64_C(0x9436c076, 0c86e30c), -319, -77}, - {GRISU_UINT64_C(0xb9447093, 8fa89bcf), -316, -76}, - {GRISU_UINT64_C(0xe7958cb8, 7392c2c3), -313, -75}, - {GRISU_UINT64_C(0x90bd77f3, 483bb9ba), -309, -74}, - {GRISU_UINT64_C(0xb4ecd5f0, 1a4aa828), -306, -73}, - {GRISU_UINT64_C(0xe2280b6c, 20dd5232), -303, -72}, - {GRISU_UINT64_C(0x8d590723, 948a535f), -299, -71}, - {GRISU_UINT64_C(0xb0af48ec, 79ace837), -296, -70}, - {GRISU_UINT64_C(0xdcdb1b27, 98182245), -293, -69}, - {GRISU_UINT64_C(0x8a08f0f8, bf0f156b), -289, -68}, - {GRISU_UINT64_C(0xac8b2d36, eed2dac6), -286, -67}, - {GRISU_UINT64_C(0xd7adf884, aa879177), -283, -66}, - {GRISU_UINT64_C(0x86ccbb52, ea94baeb), -279, -65}, - {GRISU_UINT64_C(0xa87fea27, a539e9a5), -276, -64}, - {GRISU_UINT64_C(0xd29fe4b1, 8e88640f), -273, -63}, - {GRISU_UINT64_C(0x83a3eeee, f9153e89), -269, -62}, - {GRISU_UINT64_C(0xa48ceaaa, b75a8e2b), -266, -61}, - {GRISU_UINT64_C(0xcdb02555, 653131b6), -263, -60}, - {GRISU_UINT64_C(0x808e1755, 5f3ebf12), -259, -59}, - {GRISU_UINT64_C(0xa0b19d2a, b70e6ed6), -256, -58}, - {GRISU_UINT64_C(0xc8de0475, 64d20a8c), -253, -57}, - {GRISU_UINT64_C(0xfb158592, be068d2f), -250, -56}, - {GRISU_UINT64_C(0x9ced737b, b6c4183d), -246, -55}, - {GRISU_UINT64_C(0xc428d05a, a4751e4d), -243, -54}, - {GRISU_UINT64_C(0xf5330471, 4d9265e0), -240, -53}, - {GRISU_UINT64_C(0x993fe2c6, d07b7fac), -236, -52}, - {GRISU_UINT64_C(0xbf8fdb78, 849a5f97), -233, -51}, - {GRISU_UINT64_C(0xef73d256, a5c0f77d), -230, -50}, - {GRISU_UINT64_C(0x95a86376, 27989aae), -226, -49}, - {GRISU_UINT64_C(0xbb127c53, b17ec159), -223, -48}, - {GRISU_UINT64_C(0xe9d71b68, 9dde71b0), -220, -47}, - {GRISU_UINT64_C(0x92267121, 62ab070e), -216, -46}, - {GRISU_UINT64_C(0xb6b00d69, bb55c8d1), -213, -45}, - {GRISU_UINT64_C(0xe45c10c4, 2a2b3b06), -210, -44}, - {GRISU_UINT64_C(0x8eb98a7a, 9a5b04e3), -206, -43}, - {GRISU_UINT64_C(0xb267ed19, 40f1c61c), -203, -42}, - {GRISU_UINT64_C(0xdf01e85f, 912e37a3), -200, -41}, - {GRISU_UINT64_C(0x8b61313b, babce2c6), -196, -40}, - {GRISU_UINT64_C(0xae397d8a, a96c1b78), -193, -39}, - {GRISU_UINT64_C(0xd9c7dced, 53c72256), -190, -38}, - {GRISU_UINT64_C(0x881cea14, 545c7575), -186, -37}, - {GRISU_UINT64_C(0xaa242499, 697392d3), -183, -36}, - {GRISU_UINT64_C(0xd4ad2dbf, c3d07788), -180, -35}, - {GRISU_UINT64_C(0x84ec3c97, da624ab5), -176, -34}, - {GRISU_UINT64_C(0xa6274bbd, d0fadd62), -173, -33}, - {GRISU_UINT64_C(0xcfb11ead, 453994ba), -170, -32}, - {GRISU_UINT64_C(0x81ceb32c, 4b43fcf5), -166, -31}, - {GRISU_UINT64_C(0xa2425ff7, 5e14fc32), -163, -30}, - {GRISU_UINT64_C(0xcad2f7f5, 359a3b3e), -160, -29}, - {GRISU_UINT64_C(0xfd87b5f2, 8300ca0e), -157, -28}, - {GRISU_UINT64_C(0x9e74d1b7, 91e07e48), -153, -27}, - {GRISU_UINT64_C(0xc6120625, 76589ddb), -150, -26}, - {GRISU_UINT64_C(0xf79687ae, d3eec551), -147, -25}, - {GRISU_UINT64_C(0x9abe14cd, 44753b53), -143, -24}, - {GRISU_UINT64_C(0xc16d9a00, 95928a27), -140, -23}, - {GRISU_UINT64_C(0xf1c90080, baf72cb1), -137, -22}, - {GRISU_UINT64_C(0x971da050, 74da7bef), -133, -21}, - {GRISU_UINT64_C(0xbce50864, 92111aeb), -130, -20}, - {GRISU_UINT64_C(0xec1e4a7d, b69561a5), -127, -19}, - {GRISU_UINT64_C(0x9392ee8e, 921d5d07), -123, -18}, - {GRISU_UINT64_C(0xb877aa32, 36a4b449), -120, -17}, - {GRISU_UINT64_C(0xe69594be, c44de15b), -117, -16}, - {GRISU_UINT64_C(0x901d7cf7, 3ab0acd9), -113, -15}, - {GRISU_UINT64_C(0xb424dc35, 095cd80f), -110, -14}, - {GRISU_UINT64_C(0xe12e1342, 4bb40e13), -107, -13}, - {GRISU_UINT64_C(0x8cbccc09, 6f5088cc), -103, -12}, - {GRISU_UINT64_C(0xafebff0b, cb24aaff), -100, -11}, - {GRISU_UINT64_C(0xdbe6fece, bdedd5bf), -97, -10}, - {GRISU_UINT64_C(0x89705f41, 36b4a597), -93, -9}, - {GRISU_UINT64_C(0xabcc7711, 8461cefd), -90, -8}, - {GRISU_UINT64_C(0xd6bf94d5, e57a42bc), -87, -7}, - {GRISU_UINT64_C(0x8637bd05, af6c69b6), -83, -6}, - {GRISU_UINT64_C(0xa7c5ac47, 1b478423), -80, -5}, - {GRISU_UINT64_C(0xd1b71758, e219652c), -77, -4}, - {GRISU_UINT64_C(0x83126e97, 8d4fdf3b), -73, -3}, - {GRISU_UINT64_C(0xa3d70a3d, 70a3d70a), -70, -2}, - {GRISU_UINT64_C(0xcccccccc, cccccccd), -67, -1}, - {GRISU_UINT64_C(0x80000000, 00000000), -63, 0}, - {GRISU_UINT64_C(0xa0000000, 00000000), -60, 1}, - {GRISU_UINT64_C(0xc8000000, 00000000), -57, 2}, - {GRISU_UINT64_C(0xfa000000, 00000000), -54, 3}, - {GRISU_UINT64_C(0x9c400000, 00000000), -50, 4}, - {GRISU_UINT64_C(0xc3500000, 00000000), -47, 5}, - {GRISU_UINT64_C(0xf4240000, 00000000), -44, 6}, - {GRISU_UINT64_C(0x98968000, 00000000), -40, 7}, - {GRISU_UINT64_C(0xbebc2000, 00000000), -37, 8}, - {GRISU_UINT64_C(0xee6b2800, 00000000), -34, 9}, - {GRISU_UINT64_C(0x9502f900, 00000000), -30, 10}, - {GRISU_UINT64_C(0xba43b740, 00000000), -27, 11}, - {GRISU_UINT64_C(0xe8d4a510, 00000000), -24, 12}, - {GRISU_UINT64_C(0x9184e72a, 00000000), -20, 13}, - {GRISU_UINT64_C(0xb5e620f4, 80000000), -17, 14}, - {GRISU_UINT64_C(0xe35fa931, a0000000), -14, 15}, - {GRISU_UINT64_C(0x8e1bc9bf, 04000000), -10, 16}, - {GRISU_UINT64_C(0xb1a2bc2e, c5000000), -7, 17}, - {GRISU_UINT64_C(0xde0b6b3a, 76400000), -4, 18}, - {GRISU_UINT64_C(0x8ac72304, 89e80000), 0, 19}, - {GRISU_UINT64_C(0xad78ebc5, ac620000), 3, 20}, - {GRISU_UINT64_C(0xd8d726b7, 177a8000), 6, 21}, - {GRISU_UINT64_C(0x87867832, 6eac9000), 10, 22}, - {GRISU_UINT64_C(0xa968163f, 0a57b400), 13, 23}, - {GRISU_UINT64_C(0xd3c21bce, cceda100), 16, 24}, - {GRISU_UINT64_C(0x84595161, 401484a0), 20, 25}, - {GRISU_UINT64_C(0xa56fa5b9, 9019a5c8), 23, 26}, - {GRISU_UINT64_C(0xcecb8f27, f4200f3a), 26, 27}, - {GRISU_UINT64_C(0x813f3978, f8940984), 30, 28}, - {GRISU_UINT64_C(0xa18f07d7, 36b90be5), 33, 29}, - {GRISU_UINT64_C(0xc9f2c9cd, 04674edf), 36, 30}, - {GRISU_UINT64_C(0xfc6f7c40, 45812296), 39, 31}, - {GRISU_UINT64_C(0x9dc5ada8, 2b70b59e), 43, 32}, - {GRISU_UINT64_C(0xc5371912, 364ce305), 46, 33}, - {GRISU_UINT64_C(0xf684df56, c3e01bc7), 49, 34}, - {GRISU_UINT64_C(0x9a130b96, 3a6c115c), 53, 35}, - {GRISU_UINT64_C(0xc097ce7b, c90715b3), 56, 36}, - {GRISU_UINT64_C(0xf0bdc21a, bb48db20), 59, 37}, - {GRISU_UINT64_C(0x96769950, b50d88f4), 63, 38}, - {GRISU_UINT64_C(0xbc143fa4, e250eb31), 66, 39}, - {GRISU_UINT64_C(0xeb194f8e, 1ae525fd), 69, 40}, - {GRISU_UINT64_C(0x92efd1b8, d0cf37be), 73, 41}, - {GRISU_UINT64_C(0xb7abc627, 050305ae), 76, 42}, - {GRISU_UINT64_C(0xe596b7b0, c643c719), 79, 43}, - {GRISU_UINT64_C(0x8f7e32ce, 7bea5c70), 83, 44}, - {GRISU_UINT64_C(0xb35dbf82, 1ae4f38c), 86, 45}, - {GRISU_UINT64_C(0xe0352f62, a19e306f), 89, 46}, - {GRISU_UINT64_C(0x8c213d9d, a502de45), 93, 47}, - {GRISU_UINT64_C(0xaf298d05, 0e4395d7), 96, 48}, - {GRISU_UINT64_C(0xdaf3f046, 51d47b4c), 99, 49}, - {GRISU_UINT64_C(0x88d8762b, f324cd10), 103, 50}, - {GRISU_UINT64_C(0xab0e93b6, efee0054), 106, 51}, - {GRISU_UINT64_C(0xd5d238a4, abe98068), 109, 52}, - {GRISU_UINT64_C(0x85a36366, eb71f041), 113, 53}, - {GRISU_UINT64_C(0xa70c3c40, a64e6c52), 116, 54}, - {GRISU_UINT64_C(0xd0cf4b50, cfe20766), 119, 55}, - {GRISU_UINT64_C(0x82818f12, 81ed44a0), 123, 56}, - {GRISU_UINT64_C(0xa321f2d7, 226895c8), 126, 57}, - {GRISU_UINT64_C(0xcbea6f8c, eb02bb3a), 129, 58}, - {GRISU_UINT64_C(0xfee50b70, 25c36a08), 132, 59}, - {GRISU_UINT64_C(0x9f4f2726, 179a2245), 136, 60}, - {GRISU_UINT64_C(0xc722f0ef, 9d80aad6), 139, 61}, - {GRISU_UINT64_C(0xf8ebad2b, 84e0d58c), 142, 62}, - {GRISU_UINT64_C(0x9b934c3b, 330c8577), 146, 63}, - {GRISU_UINT64_C(0xc2781f49, ffcfa6d5), 149, 64}, - {GRISU_UINT64_C(0xf316271c, 7fc3908b), 152, 65}, - {GRISU_UINT64_C(0x97edd871, cfda3a57), 156, 66}, - {GRISU_UINT64_C(0xbde94e8e, 43d0c8ec), 159, 67}, - {GRISU_UINT64_C(0xed63a231, d4c4fb27), 162, 68}, - {GRISU_UINT64_C(0x945e455f, 24fb1cf9), 166, 69}, - {GRISU_UINT64_C(0xb975d6b6, ee39e437), 169, 70}, - {GRISU_UINT64_C(0xe7d34c64, a9c85d44), 172, 71}, - {GRISU_UINT64_C(0x90e40fbe, ea1d3a4b), 176, 72}, - {GRISU_UINT64_C(0xb51d13ae, a4a488dd), 179, 73}, - {GRISU_UINT64_C(0xe264589a, 4dcdab15), 182, 74}, - {GRISU_UINT64_C(0x8d7eb760, 70a08aed), 186, 75}, - {GRISU_UINT64_C(0xb0de6538, 8cc8ada8), 189, 76}, - {GRISU_UINT64_C(0xdd15fe86, affad912), 192, 77}, - {GRISU_UINT64_C(0x8a2dbf14, 2dfcc7ab), 196, 78}, - {GRISU_UINT64_C(0xacb92ed9, 397bf996), 199, 79}, - {GRISU_UINT64_C(0xd7e77a8f, 87daf7fc), 202, 80}, - {GRISU_UINT64_C(0x86f0ac99, b4e8dafd), 206, 81}, - {GRISU_UINT64_C(0xa8acd7c0, 222311bd), 209, 82}, - {GRISU_UINT64_C(0xd2d80db0, 2aabd62c), 212, 83}, - {GRISU_UINT64_C(0x83c7088e, 1aab65db), 216, 84}, - {GRISU_UINT64_C(0xa4b8cab1, a1563f52), 219, 85}, - {GRISU_UINT64_C(0xcde6fd5e, 09abcf27), 222, 86}, - {GRISU_UINT64_C(0x80b05e5a, c60b6178), 226, 87}, - {GRISU_UINT64_C(0xa0dc75f1, 778e39d6), 229, 88}, - {GRISU_UINT64_C(0xc913936d, d571c84c), 232, 89}, - {GRISU_UINT64_C(0xfb587849, 4ace3a5f), 235, 90}, - {GRISU_UINT64_C(0x9d174b2d, cec0e47b), 239, 91}, - {GRISU_UINT64_C(0xc45d1df9, 42711d9a), 242, 92}, - {GRISU_UINT64_C(0xf5746577, 930d6501), 245, 93}, - {GRISU_UINT64_C(0x9968bf6a, bbe85f20), 249, 94}, - {GRISU_UINT64_C(0xbfc2ef45, 6ae276e9), 252, 95}, - {GRISU_UINT64_C(0xefb3ab16, c59b14a3), 255, 96}, - {GRISU_UINT64_C(0x95d04aee, 3b80ece6), 259, 97}, - {GRISU_UINT64_C(0xbb445da9, ca61281f), 262, 98}, - {GRISU_UINT64_C(0xea157514, 3cf97227), 265, 99}, - {GRISU_UINT64_C(0x924d692c, a61be758), 269, 100}, - {GRISU_UINT64_C(0xb6e0c377, cfa2e12e), 272, 101}, - {GRISU_UINT64_C(0xe498f455, c38b997a), 275, 102}, - {GRISU_UINT64_C(0x8edf98b5, 9a373fec), 279, 103}, - {GRISU_UINT64_C(0xb2977ee3, 00c50fe7), 282, 104}, - {GRISU_UINT64_C(0xdf3d5e9b, c0f653e1), 285, 105}, - {GRISU_UINT64_C(0x8b865b21, 5899f46d), 289, 106}, - {GRISU_UINT64_C(0xae67f1e9, aec07188), 292, 107}, - {GRISU_UINT64_C(0xda01ee64, 1a708dea), 295, 108}, - {GRISU_UINT64_C(0x884134fe, 908658b2), 299, 109}, - {GRISU_UINT64_C(0xaa51823e, 34a7eedf), 302, 110}, - {GRISU_UINT64_C(0xd4e5e2cd, c1d1ea96), 305, 111}, - {GRISU_UINT64_C(0x850fadc0, 9923329e), 309, 112}, - {GRISU_UINT64_C(0xa6539930, bf6bff46), 312, 113}, - {GRISU_UINT64_C(0xcfe87f7c, ef46ff17), 315, 114}, - {GRISU_UINT64_C(0x81f14fae, 158c5f6e), 319, 115}, - {GRISU_UINT64_C(0xa26da399, 9aef774a), 322, 116}, - {GRISU_UINT64_C(0xcb090c80, 01ab551c), 325, 117}, - {GRISU_UINT64_C(0xfdcb4fa0, 02162a63), 328, 118}, - {GRISU_UINT64_C(0x9e9f11c4, 014dda7e), 332, 119}, - {GRISU_UINT64_C(0xc646d635, 01a1511e), 335, 120}, - {GRISU_UINT64_C(0xf7d88bc2, 4209a565), 338, 121}, - {GRISU_UINT64_C(0x9ae75759, 6946075f), 342, 122}, - {GRISU_UINT64_C(0xc1a12d2f, c3978937), 345, 123}, - {GRISU_UINT64_C(0xf209787b, b47d6b85), 348, 124}, - {GRISU_UINT64_C(0x9745eb4d, 50ce6333), 352, 125}, - {GRISU_UINT64_C(0xbd176620, a501fc00), 355, 126}, - {GRISU_UINT64_C(0xec5d3fa8, ce427b00), 358, 127}, - {GRISU_UINT64_C(0x93ba47c9, 80e98ce0), 362, 128}, - {GRISU_UINT64_C(0xb8a8d9bb, e123f018), 365, 129}, - {GRISU_UINT64_C(0xe6d3102a, d96cec1e), 368, 130}, - {GRISU_UINT64_C(0x9043ea1a, c7e41393), 372, 131}, - {GRISU_UINT64_C(0xb454e4a1, 79dd1877), 375, 132}, - {GRISU_UINT64_C(0xe16a1dc9, d8545e95), 378, 133}, - {GRISU_UINT64_C(0x8ce2529e, 2734bb1d), 382, 134}, - {GRISU_UINT64_C(0xb01ae745, b101e9e4), 385, 135}, - {GRISU_UINT64_C(0xdc21a117, 1d42645d), 388, 136}, - {GRISU_UINT64_C(0x899504ae, 72497eba), 392, 137}, - {GRISU_UINT64_C(0xabfa45da, 0edbde69), 395, 138}, - {GRISU_UINT64_C(0xd6f8d750, 9292d603), 398, 139}, - {GRISU_UINT64_C(0x865b8692, 5b9bc5c2), 402, 140}, - {GRISU_UINT64_C(0xa7f26836, f282b733), 405, 141}, - {GRISU_UINT64_C(0xd1ef0244, af2364ff), 408, 142}, - {GRISU_UINT64_C(0x8335616a, ed761f1f), 412, 143}, - {GRISU_UINT64_C(0xa402b9c5, a8d3a6e7), 415, 144}, - {GRISU_UINT64_C(0xcd036837, 130890a1), 418, 145}, - {GRISU_UINT64_C(0x80222122, 6be55a65), 422, 146}, - {GRISU_UINT64_C(0xa02aa96b, 06deb0fe), 425, 147}, - {GRISU_UINT64_C(0xc83553c5, c8965d3d), 428, 148}, - {GRISU_UINT64_C(0xfa42a8b7, 3abbf48d), 431, 149}, - {GRISU_UINT64_C(0x9c69a972, 84b578d8), 435, 150}, - {GRISU_UINT64_C(0xc38413cf, 25e2d70e), 438, 151}, - {GRISU_UINT64_C(0xf46518c2, ef5b8cd1), 441, 152}, - {GRISU_UINT64_C(0x98bf2f79, d5993803), 445, 153}, - {GRISU_UINT64_C(0xbeeefb58, 4aff8604), 448, 154}, - {GRISU_UINT64_C(0xeeaaba2e, 5dbf6785), 451, 155}, - {GRISU_UINT64_C(0x952ab45c, fa97a0b3), 455, 156}, - {GRISU_UINT64_C(0xba756174, 393d88e0), 458, 157}, - {GRISU_UINT64_C(0xe912b9d1, 478ceb17), 461, 158}, - {GRISU_UINT64_C(0x91abb422, ccb812ef), 465, 159}, - {GRISU_UINT64_C(0xb616a12b, 7fe617aa), 468, 160}, - {GRISU_UINT64_C(0xe39c4976, 5fdf9d95), 471, 161}, - {GRISU_UINT64_C(0x8e41ade9, fbebc27d), 475, 162}, - {GRISU_UINT64_C(0xb1d21964, 7ae6b31c), 478, 163}, - {GRISU_UINT64_C(0xde469fbd, 99a05fe3), 481, 164}, - {GRISU_UINT64_C(0x8aec23d6, 80043bee), 485, 165}, - {GRISU_UINT64_C(0xada72ccc, 20054aea), 488, 166}, - {GRISU_UINT64_C(0xd910f7ff, 28069da4), 491, 167}, - {GRISU_UINT64_C(0x87aa9aff, 79042287), 495, 168}, - {GRISU_UINT64_C(0xa99541bf, 57452b28), 498, 169}, - {GRISU_UINT64_C(0xd3fa922f, 2d1675f2), 501, 170}, - {GRISU_UINT64_C(0x847c9b5d, 7c2e09b7), 505, 171}, - {GRISU_UINT64_C(0xa59bc234, db398c25), 508, 172}, - {GRISU_UINT64_C(0xcf02b2c2, 1207ef2f), 511, 173}, - {GRISU_UINT64_C(0x8161afb9, 4b44f57d), 515, 174}, - {GRISU_UINT64_C(0xa1ba1ba7, 9e1632dc), 518, 175}, - {GRISU_UINT64_C(0xca28a291, 859bbf93), 521, 176}, - {GRISU_UINT64_C(0xfcb2cb35, e702af78), 524, 177}, - {GRISU_UINT64_C(0x9defbf01, b061adab), 528, 178}, - {GRISU_UINT64_C(0xc56baec2, 1c7a1916), 531, 179}, - {GRISU_UINT64_C(0xf6c69a72, a3989f5c), 534, 180}, - {GRISU_UINT64_C(0x9a3c2087, a63f6399), 538, 181}, - {GRISU_UINT64_C(0xc0cb28a9, 8fcf3c80), 541, 182}, - {GRISU_UINT64_C(0xf0fdf2d3, f3c30b9f), 544, 183}, - {GRISU_UINT64_C(0x969eb7c4, 7859e744), 548, 184}, - {GRISU_UINT64_C(0xbc4665b5, 96706115), 551, 185}, - {GRISU_UINT64_C(0xeb57ff22, fc0c795a), 554, 186}, - {GRISU_UINT64_C(0x9316ff75, dd87cbd8), 558, 187}, - {GRISU_UINT64_C(0xb7dcbf53, 54e9bece), 561, 188}, - {GRISU_UINT64_C(0xe5d3ef28, 2a242e82), 564, 189}, - {GRISU_UINT64_C(0x8fa47579, 1a569d11), 568, 190}, - {GRISU_UINT64_C(0xb38d92d7, 60ec4455), 571, 191}, - {GRISU_UINT64_C(0xe070f78d, 3927556b), 574, 192}, - {GRISU_UINT64_C(0x8c469ab8, 43b89563), 578, 193}, - {GRISU_UINT64_C(0xaf584166, 54a6babb), 581, 194}, - {GRISU_UINT64_C(0xdb2e51bf, e9d0696a), 584, 195}, - {GRISU_UINT64_C(0x88fcf317, f22241e2), 588, 196}, - {GRISU_UINT64_C(0xab3c2fdd, eeaad25b), 591, 197}, - {GRISU_UINT64_C(0xd60b3bd5, 6a5586f2), 594, 198}, - {GRISU_UINT64_C(0x85c70565, 62757457), 598, 199}, - {GRISU_UINT64_C(0xa738c6be, bb12d16d), 601, 200}, - {GRISU_UINT64_C(0xd106f86e, 69d785c8), 604, 201}, - {GRISU_UINT64_C(0x82a45b45, 0226b39d), 608, 202}, - {GRISU_UINT64_C(0xa34d7216, 42b06084), 611, 203}, - {GRISU_UINT64_C(0xcc20ce9b, d35c78a5), 614, 204}, - {GRISU_UINT64_C(0xff290242, c83396ce), 617, 205}, - {GRISU_UINT64_C(0x9f79a169, bd203e41), 621, 206}, - {GRISU_UINT64_C(0xc75809c4, 2c684dd1), 624, 207}, - {GRISU_UINT64_C(0xf92e0c35, 37826146), 627, 208}, - {GRISU_UINT64_C(0x9bbcc7a1, 42b17ccc), 631, 209}, - {GRISU_UINT64_C(0xc2abf989, 935ddbfe), 634, 210}, - {GRISU_UINT64_C(0xf356f7eb, f83552fe), 637, 211}, - {GRISU_UINT64_C(0x98165af3, 7b2153df), 641, 212}, - {GRISU_UINT64_C(0xbe1bf1b0, 59e9a8d6), 644, 213}, - {GRISU_UINT64_C(0xeda2ee1c, 7064130c), 647, 214}, - {GRISU_UINT64_C(0x9485d4d1, c63e8be8), 651, 215}, - {GRISU_UINT64_C(0xb9a74a06, 37ce2ee1), 654, 216}, - {GRISU_UINT64_C(0xe8111c87, c5c1ba9a), 657, 217}, - {GRISU_UINT64_C(0x910ab1d4, db9914a0), 661, 218}, - {GRISU_UINT64_C(0xb54d5e4a, 127f59c8), 664, 219}, - {GRISU_UINT64_C(0xe2a0b5dc, 971f303a), 667, 220}, - {GRISU_UINT64_C(0x8da471a9, de737e24), 671, 221}, - {GRISU_UINT64_C(0xb10d8e14, 56105dad), 674, 222}, - {GRISU_UINT64_C(0xdd50f199, 6b947519), 677, 223}, - {GRISU_UINT64_C(0x8a5296ff, e33cc930), 681, 224}, - {GRISU_UINT64_C(0xace73cbf, dc0bfb7b), 684, 225}, - {GRISU_UINT64_C(0xd8210bef, d30efa5a), 687, 226}, - {GRISU_UINT64_C(0x8714a775, e3e95c78), 691, 227}, - {GRISU_UINT64_C(0xa8d9d153, 5ce3b396), 694, 228}, - {GRISU_UINT64_C(0xd31045a8, 341ca07c), 697, 229}, - {GRISU_UINT64_C(0x83ea2b89, 2091e44e), 701, 230}, - {GRISU_UINT64_C(0xa4e4b66b, 68b65d61), 704, 231}, - {GRISU_UINT64_C(0xce1de406, 42e3f4b9), 707, 232}, - {GRISU_UINT64_C(0x80d2ae83, e9ce78f4), 711, 233}, - {GRISU_UINT64_C(0xa1075a24, e4421731), 714, 234}, - {GRISU_UINT64_C(0xc94930ae, 1d529cfd), 717, 235}, - {GRISU_UINT64_C(0xfb9b7cd9, a4a7443c), 720, 236}, - {GRISU_UINT64_C(0x9d412e08, 06e88aa6), 724, 237}, - {GRISU_UINT64_C(0xc491798a, 08a2ad4f), 727, 238}, - {GRISU_UINT64_C(0xf5b5d7ec, 8acb58a3), 730, 239}, - {GRISU_UINT64_C(0x9991a6f3, d6bf1766), 734, 240}, - {GRISU_UINT64_C(0xbff610b0, cc6edd3f), 737, 241}, - {GRISU_UINT64_C(0xeff394dc, ff8a948f), 740, 242}, - {GRISU_UINT64_C(0x95f83d0a, 1fb69cd9), 744, 243}, - {GRISU_UINT64_C(0xbb764c4c, a7a44410), 747, 244}, - {GRISU_UINT64_C(0xea53df5f, d18d5514), 750, 245}, - {GRISU_UINT64_C(0x92746b9b, e2f8552c), 754, 246}, - {GRISU_UINT64_C(0xb7118682, dbb66a77), 757, 247}, - {GRISU_UINT64_C(0xe4d5e823, 92a40515), 760, 248}, - {GRISU_UINT64_C(0x8f05b116, 3ba6832d), 764, 249}, - {GRISU_UINT64_C(0xb2c71d5b, ca9023f8), 767, 250}, - {GRISU_UINT64_C(0xdf78e4b2, bd342cf7), 770, 251}, - {GRISU_UINT64_C(0x8bab8eef, b6409c1a), 774, 252}, - {GRISU_UINT64_C(0xae9672ab, a3d0c321), 777, 253}, - {GRISU_UINT64_C(0xda3c0f56, 8cc4f3e9), 780, 254}, - {GRISU_UINT64_C(0x88658996, 17fb1871), 784, 255}, - {GRISU_UINT64_C(0xaa7eebfb, 9df9de8e), 787, 256}, - {GRISU_UINT64_C(0xd51ea6fa, 85785631), 790, 257}, - {GRISU_UINT64_C(0x8533285c, 936b35df), 794, 258}, - {GRISU_UINT64_C(0xa67ff273, b8460357), 797, 259}, - {GRISU_UINT64_C(0xd01fef10, a657842c), 800, 260}, - {GRISU_UINT64_C(0x8213f56a, 67f6b29c), 804, 261}, - {GRISU_UINT64_C(0xa298f2c5, 01f45f43), 807, 262}, - {GRISU_UINT64_C(0xcb3f2f76, 42717713), 810, 263}, - {GRISU_UINT64_C(0xfe0efb53, d30dd4d8), 813, 264}, - {GRISU_UINT64_C(0x9ec95d14, 63e8a507), 817, 265}, - {GRISU_UINT64_C(0xc67bb459, 7ce2ce49), 820, 266}, - {GRISU_UINT64_C(0xf81aa16f, dc1b81db), 823, 267}, - {GRISU_UINT64_C(0x9b10a4e5, e9913129), 827, 268}, - {GRISU_UINT64_C(0xc1d4ce1f, 63f57d73), 830, 269}, - {GRISU_UINT64_C(0xf24a01a7, 3cf2dcd0), 833, 270}, - {GRISU_UINT64_C(0x976e4108, 8617ca02), 837, 271}, - {GRISU_UINT64_C(0xbd49d14a, a79dbc82), 840, 272}, - {GRISU_UINT64_C(0xec9c459d, 51852ba3), 843, 273}, - {GRISU_UINT64_C(0x93e1ab82, 52f33b46), 847, 274}, - {GRISU_UINT64_C(0xb8da1662, e7b00a17), 850, 275}, - {GRISU_UINT64_C(0xe7109bfb, a19c0c9d), 853, 276}, - {GRISU_UINT64_C(0x906a617d, 450187e2), 857, 277}, - {GRISU_UINT64_C(0xb484f9dc, 9641e9db), 860, 278}, - {GRISU_UINT64_C(0xe1a63853, bbd26451), 863, 279}, - {GRISU_UINT64_C(0x8d07e334, 55637eb3), 867, 280}, - {GRISU_UINT64_C(0xb049dc01, 6abc5e60), 870, 281}, - {GRISU_UINT64_C(0xdc5c5301, c56b75f7), 873, 282}, - {GRISU_UINT64_C(0x89b9b3e1, 1b6329bb), 877, 283}, - {GRISU_UINT64_C(0xac2820d9, 623bf429), 880, 284}, - {GRISU_UINT64_C(0xd732290f, bacaf134), 883, 285}, - {GRISU_UINT64_C(0x867f59a9, d4bed6c0), 887, 286}, - {GRISU_UINT64_C(0xa81f3014, 49ee8c70), 890, 287}, - {GRISU_UINT64_C(0xd226fc19, 5c6a2f8c), 893, 288}, - {GRISU_UINT64_C(0x83585d8f, d9c25db8), 897, 289}, - {GRISU_UINT64_C(0xa42e74f3, d032f526), 900, 290}, - {GRISU_UINT64_C(0xcd3a1230, c43fb26f), 903, 291}, - {GRISU_UINT64_C(0x80444b5e, 7aa7cf85), 907, 292}, - {GRISU_UINT64_C(0xa0555e36, 1951c367), 910, 293}, - {GRISU_UINT64_C(0xc86ab5c3, 9fa63441), 913, 294}, - {GRISU_UINT64_C(0xfa856334, 878fc151), 916, 295}, - {GRISU_UINT64_C(0x9c935e00, d4b9d8d2), 920, 296}, - {GRISU_UINT64_C(0xc3b83581, 09e84f07), 923, 297}, - {GRISU_UINT64_C(0xf4a642e1, 4c6262c9), 926, 298}, - {GRISU_UINT64_C(0x98e7e9cc, cfbd7dbe), 930, 299}, - {GRISU_UINT64_C(0xbf21e440, 03acdd2d), 933, 300}, - {GRISU_UINT64_C(0xeeea5d50, 04981478), 936, 301}, - {GRISU_UINT64_C(0x95527a52, 02df0ccb), 940, 302}, - {GRISU_UINT64_C(0xbaa718e6, 8396cffe), 943, 303}, - {GRISU_UINT64_C(0xe950df20, 247c83fd), 946, 304}, - {GRISU_UINT64_C(0x91d28b74, 16cdd27e), 950, 305}, - {GRISU_UINT64_C(0xb6472e51, 1c81471e), 953, 306}, - {GRISU_UINT64_C(0xe3d8f9e5, 63a198e5), 956, 307}, - {GRISU_UINT64_C(0x8e679c2f, 5e44ff8f), 960, 308}, - {GRISU_UINT64_C(0xb201833b, 35d63f73), 963, 309}, - {GRISU_UINT64_C(0xde81e40a, 034bcf50), 966, 310}, - {GRISU_UINT64_C(0x8b112e86, 420f6192), 970, 311}, - {GRISU_UINT64_C(0xadd57a27, d29339f6), 973, 312}, - {GRISU_UINT64_C(0xd94ad8b1, c7380874), 976, 313}, - {GRISU_UINT64_C(0x87cec76f, 1c830549), 980, 314}, - {GRISU_UINT64_C(0xa9c2794a, e3a3c69b), 983, 315}, - {GRISU_UINT64_C(0xd433179d, 9c8cb841), 986, 316}, - {GRISU_UINT64_C(0x849feec2, 81d7f329), 990, 317}, - {GRISU_UINT64_C(0xa5c7ea73, 224deff3), 993, 318}, - {GRISU_UINT64_C(0xcf39e50f, eae16bf0), 996, 319}, - {GRISU_UINT64_C(0x81842f29, f2cce376), 1000, 320}, - {GRISU_UINT64_C(0xa1e53af4, 6f801c53), 1003, 321}, - {GRISU_UINT64_C(0xca5e89b1, 8b602368), 1006, 322}, - {GRISU_UINT64_C(0xfcf62c1d, ee382c42), 1009, 323}, - {GRISU_UINT64_C(0x9e19db92, b4e31ba9), 1013, 324}, - {GRISU_UINT64_C(0xc5a05277, 621be294), 1016, 325}, - {GRISU_UINT64_C(0xf7086715, 3aa2db39), 1019, 326}, - {GRISU_UINT64_C(0x9a65406d, 44a5c903), 1023, 327}, - {GRISU_UINT64_C(0xc0fe9088, 95cf3b44), 1026, 328}, - {GRISU_UINT64_C(0xf13e34aa, bb430a15), 1029, 329}, - {GRISU_UINT64_C(0x96c6e0ea, b509e64d), 1033, 330}, - {GRISU_UINT64_C(0xbc789925, 624c5fe1), 1036, 331}, - {GRISU_UINT64_C(0xeb96bf6e, badf77d9), 1039, 332}, - {GRISU_UINT64_C(0x933e37a5, 34cbaae8), 1043, 333}, - {GRISU_UINT64_C(0xb80dc58e, 81fe95a1), 1046, 334}, - {GRISU_UINT64_C(0xe61136f2, 227e3b0a), 1049, 335}, - {GRISU_UINT64_C(0x8fcac257, 558ee4e6), 1053, 336}, - {GRISU_UINT64_C(0xb3bd72ed, 2af29e20), 1056, 337}, - {GRISU_UINT64_C(0xe0accfa8, 75af45a8), 1059, 338}, - {GRISU_UINT64_C(0x8c6c01c9, 498d8b89), 1063, 339}, - {GRISU_UINT64_C(0xaf87023b, 9bf0ee6b), 1066, 340}, - {GRISU_UINT64_C(0xdb68c2ca, 82ed2a06), 1069, 341}, - {GRISU_UINT64_C(0x892179be, 91d43a44), 1073, 342}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(1) = 4; -// nb elements (1): 651 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(2)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0xb3c4f1ba, 87bc8697), -1080, -306}, - {GRISU_UINT64_C(0x8c71dcd9, ba0b4926), -1073, -304}, - {GRISU_UINT64_C(0xdb71e914, 32b1a24b), -1067, -302}, - {GRISU_UINT64_C(0xab70fe17, c79ac6ca), -1060, -300}, - {GRISU_UINT64_C(0x85f04682, 93f0eb4e), -1053, -298}, - {GRISU_UINT64_C(0xd1476e2c, 07286faa), -1047, -296}, - {GRISU_UINT64_C(0xa37fce12, 6597973d), -1040, -294}, - {GRISU_UINT64_C(0xff77b1fc, bebcdc4f), -1034, -292}, - {GRISU_UINT64_C(0xc795830d, 75038c1e), -1027, -290}, - {GRISU_UINT64_C(0x9becce62, 836ac577), -1020, -288}, - {GRISU_UINT64_C(0xf3a20279, ed56d48a), -1014, -286}, - {GRISU_UINT64_C(0xbe5691ef, 416bd60c), -1007, -284}, - {GRISU_UINT64_C(0x94b3a202, eb1c3f39), -1000, -282}, - {GRISU_UINT64_C(0xe858ad24, 8f5c22ca), -994, -280}, - {GRISU_UINT64_C(0xb5854744, 8ffffb2e), -987, -278}, - {GRISU_UINT64_C(0x8dd01fad, 907ffc3c), -980, -276}, - {GRISU_UINT64_C(0xdd95317f, 31c7fa1d), -974, -274}, - {GRISU_UINT64_C(0xad1c8eab, 5ee43b67), -967, -272}, - {GRISU_UINT64_C(0x873e4f75, e2224e68), -960, -270}, - {GRISU_UINT64_C(0xd3515c28, 31559a83), -954, -268}, - {GRISU_UINT64_C(0xa5178fff, 668ae0b6), -947, -266}, - {GRISU_UINT64_C(0x80fa687f, 881c7f8e), -940, -264}, - {GRISU_UINT64_C(0xc9874347, 44ac874f), -934, -262}, - {GRISU_UINT64_C(0x9d71ac8f, ada6c9b5), -927, -260}, - {GRISU_UINT64_C(0xf6019da0, 7f549b2b), -921, -258}, - {GRISU_UINT64_C(0xc0314325, 637a193a), -914, -256}, - {GRISU_UINT64_C(0x96267c75, 35b763b5), -907, -254}, - {GRISU_UINT64_C(0xea9c2277, 23ee8bcb), -901, -252}, - {GRISU_UINT64_C(0xb749faed, 14125d37), -894, -250}, - {GRISU_UINT64_C(0x8f31cc09, 37ae58d3), -887, -248}, - {GRISU_UINT64_C(0xdfbdcece, 67006ac9), -881, -246}, - {GRISU_UINT64_C(0xaecc4991, 4078536d), -874, -244}, - {GRISU_UINT64_C(0x888f9979, 7a5e012d), -867, -242}, - {GRISU_UINT64_C(0xd5605fcd, cf32e1d7), -861, -240}, - {GRISU_UINT64_C(0xa6b34ad8, c9dfc070), -854, -238}, - {GRISU_UINT64_C(0x823c1279, 5db6ce57), -847, -236}, - {GRISU_UINT64_C(0xcb7ddcdd, a26da269), -841, -234}, - {GRISU_UINT64_C(0x9efa548d, 26e5a6e2), -834, -232}, - {GRISU_UINT64_C(0xf867241c, 8cc6d4c1), -828, -230}, - {GRISU_UINT64_C(0xc2109436, 4dfb5637), -821, -228}, - {GRISU_UINT64_C(0x979cf3ca, 6cec5b5b), -814, -226}, - {GRISU_UINT64_C(0xece53cec, 4a314ebe), -808, -224}, - {GRISU_UINT64_C(0xb9131798, 99f68584), -801, -222}, - {GRISU_UINT64_C(0x9096ea6f, 3848984f), -794, -220}, - {GRISU_UINT64_C(0xe1ebce4d, c7f16dfc), -788, -218}, - {GRISU_UINT64_C(0xb080392c, c4349ded), -781, -216}, - {GRISU_UINT64_C(0x89e42caa, f9491b61), -774, -214}, - {GRISU_UINT64_C(0xd77485cb, 25823ac7), -768, -212}, - {GRISU_UINT64_C(0xa8530886, b54dbdec), -761, -210}, - {GRISU_UINT64_C(0x8380dea9, 3da4bc60), -754, -208}, - {GRISU_UINT64_C(0xcd795be8, 70516656), -748, -206}, - {GRISU_UINT64_C(0xa086cfcd, 97bf97f4), -741, -204}, - {GRISU_UINT64_C(0xfad2a4b1, 3d1b5d6c), -735, -202}, - {GRISU_UINT64_C(0xc3f490aa, 77bd60fd), -728, -200}, - {GRISU_UINT64_C(0x99171105, 2d8bf3c5), -721, -198}, - {GRISU_UINT64_C(0xef340a98, 172aace5), -715, -196}, - {GRISU_UINT64_C(0xbae0a846, d2195713), -708, -194}, - {GRISU_UINT64_C(0x91ff8377, 5423cc06), -701, -192}, - {GRISU_UINT64_C(0xe41f3d6a, 7377eeca), -695, -190}, - {GRISU_UINT64_C(0xb23867fb, 2a35b28e), -688, -188}, - {GRISU_UINT64_C(0x8b3c113c, 38f9f37f), -681, -186}, - {GRISU_UINT64_C(0xd98ddaee, 19068c76), -675, -184}, - {GRISU_UINT64_C(0xa9f6d30a, 038d1dbc), -668, -182}, - {GRISU_UINT64_C(0x84c8d4df, d2c63f3b), -661, -180}, - {GRISU_UINT64_C(0xcf79cc9d, b955c2cc), -655, -178}, - {GRISU_UINT64_C(0xa21727db, 38cb0030), -648, -176}, - {GRISU_UINT64_C(0xfd442e46, 88bd304b), -642, -174}, - {GRISU_UINT64_C(0xc5dd4427, 1ad3cdba), -635, -172}, - {GRISU_UINT64_C(0x9a94dd3e, 8cf578ba), -628, -170}, - {GRISU_UINT64_C(0xf18899b1, bc3f8ca2), -622, -168}, - {GRISU_UINT64_C(0xbcb2b812, db11a5de), -615, -166}, - {GRISU_UINT64_C(0x936b9fce, bb25c996), -608, -164}, - {GRISU_UINT64_C(0xe65829b3, 046b0afa), -602, -162}, - {GRISU_UINT64_C(0xb3f4e093, db73a093), -595, -160}, - {GRISU_UINT64_C(0x8c974f73, 83725573), -588, -158}, - {GRISU_UINT64_C(0xdbac6c24, 7d62a584), -582, -156}, - {GRISU_UINT64_C(0xab9eb47c, 81f5114f), -575, -154}, - {GRISU_UINT64_C(0x8613fd01, 45877586), -568, -152}, - {GRISU_UINT64_C(0xd17f3b51, fca3a7a1), -562, -150}, - {GRISU_UINT64_C(0xa3ab6658, 0d5fdaf6), -555, -148}, - {GRISU_UINT64_C(0xffbbcfe9, 94e5c620), -549, -146}, - {GRISU_UINT64_C(0xc7caba6e, 7c5382c9), -542, -144}, - {GRISU_UINT64_C(0x9c1661a6, 51213e2d), -535, -142}, - {GRISU_UINT64_C(0xf3e2f893, dec3f126), -529, -140}, - {GRISU_UINT64_C(0xbe895233, 86091466), -522, -138}, - {GRISU_UINT64_C(0x94db4838, 40b717f0), -515, -136}, - {GRISU_UINT64_C(0xe896a0d7, e51e1566), -509, -134}, - {GRISU_UINT64_C(0xb5b5ada8, aaff80b8), -502, -132}, - {GRISU_UINT64_C(0x8df5efab, c5979c90), -495, -130}, - {GRISU_UINT64_C(0xddd0467c, 64bce4a1), -489, -128}, - {GRISU_UINT64_C(0xad4ab711, 2eb3929e), -482, -126}, - {GRISU_UINT64_C(0x87625f05, 6c7c4a8b), -475, -124}, - {GRISU_UINT64_C(0xd389b478, 79823479), -469, -122}, - {GRISU_UINT64_C(0xa54394fe, 1eedb8ff), -462, -120}, - {GRISU_UINT64_C(0x811ccc66, 8829b887), -455, -118}, - {GRISU_UINT64_C(0xc9bcff60, 34c13053), -449, -116}, - {GRISU_UINT64_C(0x9d9ba783, 2936edc1), -442, -114}, - {GRISU_UINT64_C(0xf64335bc, f065d37d), -436, -112}, - {GRISU_UINT64_C(0xc06481fb, 9bcf8d3a), -429, -110}, - {GRISU_UINT64_C(0x964e858c, 91ba2655), -422, -108}, - {GRISU_UINT64_C(0xeadab0ab, a3b2dbe5), -416, -106}, - {GRISU_UINT64_C(0xb77ada06, 17e3bbcb), -409, -104}, - {GRISU_UINT64_C(0x8f57fa54, c2a9eab7), -402, -102}, - {GRISU_UINT64_C(0xdff97724, 70297ebd), -396, -100}, - {GRISU_UINT64_C(0xaefae514, 77a06b04), -389, -98}, - {GRISU_UINT64_C(0x88b402f7, fd75539b), -382, -96}, - {GRISU_UINT64_C(0xd59944a3, 7c0752a2), -376, -94}, - {GRISU_UINT64_C(0xa6dfbd9f, b8e5b88f), -369, -92}, - {GRISU_UINT64_C(0x825ecc24, c8737830), -362, -90}, - {GRISU_UINT64_C(0xcbb41ef9, 79346bca), -356, -88}, - {GRISU_UINT64_C(0x9f24b832, e6b0f436), -349, -86}, - {GRISU_UINT64_C(0xf8a95fcf, 88747d94), -343, -84}, - {GRISU_UINT64_C(0xc24452da, 229b021c), -336, -82}, - {GRISU_UINT64_C(0x97c560ba, 6b0919a6), -329, -80}, - {GRISU_UINT64_C(0xed246723, 473e3813), -323, -78}, - {GRISU_UINT64_C(0xb9447093, 8fa89bcf), -316, -76}, - {GRISU_UINT64_C(0x90bd77f3, 483bb9ba), -309, -74}, - {GRISU_UINT64_C(0xe2280b6c, 20dd5232), -303, -72}, - {GRISU_UINT64_C(0xb0af48ec, 79ace837), -296, -70}, - {GRISU_UINT64_C(0x8a08f0f8, bf0f156b), -289, -68}, - {GRISU_UINT64_C(0xd7adf884, aa879177), -283, -66}, - {GRISU_UINT64_C(0xa87fea27, a539e9a5), -276, -64}, - {GRISU_UINT64_C(0x83a3eeee, f9153e89), -269, -62}, - {GRISU_UINT64_C(0xcdb02555, 653131b6), -263, -60}, - {GRISU_UINT64_C(0xa0b19d2a, b70e6ed6), -256, -58}, - {GRISU_UINT64_C(0xfb158592, be068d2f), -250, -56}, - {GRISU_UINT64_C(0xc428d05a, a4751e4d), -243, -54}, - {GRISU_UINT64_C(0x993fe2c6, d07b7fac), -236, -52}, - {GRISU_UINT64_C(0xef73d256, a5c0f77d), -230, -50}, - {GRISU_UINT64_C(0xbb127c53, b17ec159), -223, -48}, - {GRISU_UINT64_C(0x92267121, 62ab070e), -216, -46}, - {GRISU_UINT64_C(0xe45c10c4, 2a2b3b06), -210, -44}, - {GRISU_UINT64_C(0xb267ed19, 40f1c61c), -203, -42}, - {GRISU_UINT64_C(0x8b61313b, babce2c6), -196, -40}, - {GRISU_UINT64_C(0xd9c7dced, 53c72256), -190, -38}, - {GRISU_UINT64_C(0xaa242499, 697392d3), -183, -36}, - {GRISU_UINT64_C(0x84ec3c97, da624ab5), -176, -34}, - {GRISU_UINT64_C(0xcfb11ead, 453994ba), -170, -32}, - {GRISU_UINT64_C(0xa2425ff7, 5e14fc32), -163, -30}, - {GRISU_UINT64_C(0xfd87b5f2, 8300ca0e), -157, -28}, - {GRISU_UINT64_C(0xc6120625, 76589ddb), -150, -26}, - {GRISU_UINT64_C(0x9abe14cd, 44753b53), -143, -24}, - {GRISU_UINT64_C(0xf1c90080, baf72cb1), -137, -22}, - {GRISU_UINT64_C(0xbce50864, 92111aeb), -130, -20}, - {GRISU_UINT64_C(0x9392ee8e, 921d5d07), -123, -18}, - {GRISU_UINT64_C(0xe69594be, c44de15b), -117, -16}, - {GRISU_UINT64_C(0xb424dc35, 095cd80f), -110, -14}, - {GRISU_UINT64_C(0x8cbccc09, 6f5088cc), -103, -12}, - {GRISU_UINT64_C(0xdbe6fece, bdedd5bf), -97, -10}, - {GRISU_UINT64_C(0xabcc7711, 8461cefd), -90, -8}, - {GRISU_UINT64_C(0x8637bd05, af6c69b6), -83, -6}, - {GRISU_UINT64_C(0xd1b71758, e219652c), -77, -4}, - {GRISU_UINT64_C(0xa3d70a3d, 70a3d70a), -70, -2}, - {GRISU_UINT64_C(0x80000000, 00000000), -63, 0}, - {GRISU_UINT64_C(0xc8000000, 00000000), -57, 2}, - {GRISU_UINT64_C(0x9c400000, 00000000), -50, 4}, - {GRISU_UINT64_C(0xf4240000, 00000000), -44, 6}, - {GRISU_UINT64_C(0xbebc2000, 00000000), -37, 8}, - {GRISU_UINT64_C(0x9502f900, 00000000), -30, 10}, - {GRISU_UINT64_C(0xe8d4a510, 00000000), -24, 12}, - {GRISU_UINT64_C(0xb5e620f4, 80000000), -17, 14}, - {GRISU_UINT64_C(0x8e1bc9bf, 04000000), -10, 16}, - {GRISU_UINT64_C(0xde0b6b3a, 76400000), -4, 18}, - {GRISU_UINT64_C(0xad78ebc5, ac620000), 3, 20}, - {GRISU_UINT64_C(0x87867832, 6eac9000), 10, 22}, - {GRISU_UINT64_C(0xd3c21bce, cceda100), 16, 24}, - {GRISU_UINT64_C(0xa56fa5b9, 9019a5c8), 23, 26}, - {GRISU_UINT64_C(0x813f3978, f8940984), 30, 28}, - {GRISU_UINT64_C(0xc9f2c9cd, 04674edf), 36, 30}, - {GRISU_UINT64_C(0x9dc5ada8, 2b70b59e), 43, 32}, - {GRISU_UINT64_C(0xf684df56, c3e01bc7), 49, 34}, - {GRISU_UINT64_C(0xc097ce7b, c90715b3), 56, 36}, - {GRISU_UINT64_C(0x96769950, b50d88f4), 63, 38}, - {GRISU_UINT64_C(0xeb194f8e, 1ae525fd), 69, 40}, - {GRISU_UINT64_C(0xb7abc627, 050305ae), 76, 42}, - {GRISU_UINT64_C(0x8f7e32ce, 7bea5c70), 83, 44}, - {GRISU_UINT64_C(0xe0352f62, a19e306f), 89, 46}, - {GRISU_UINT64_C(0xaf298d05, 0e4395d7), 96, 48}, - {GRISU_UINT64_C(0x88d8762b, f324cd10), 103, 50}, - {GRISU_UINT64_C(0xd5d238a4, abe98068), 109, 52}, - {GRISU_UINT64_C(0xa70c3c40, a64e6c52), 116, 54}, - {GRISU_UINT64_C(0x82818f12, 81ed44a0), 123, 56}, - {GRISU_UINT64_C(0xcbea6f8c, eb02bb3a), 129, 58}, - {GRISU_UINT64_C(0x9f4f2726, 179a2245), 136, 60}, - {GRISU_UINT64_C(0xf8ebad2b, 84e0d58c), 142, 62}, - {GRISU_UINT64_C(0xc2781f49, ffcfa6d5), 149, 64}, - {GRISU_UINT64_C(0x97edd871, cfda3a57), 156, 66}, - {GRISU_UINT64_C(0xed63a231, d4c4fb27), 162, 68}, - {GRISU_UINT64_C(0xb975d6b6, ee39e437), 169, 70}, - {GRISU_UINT64_C(0x90e40fbe, ea1d3a4b), 176, 72}, - {GRISU_UINT64_C(0xe264589a, 4dcdab15), 182, 74}, - {GRISU_UINT64_C(0xb0de6538, 8cc8ada8), 189, 76}, - {GRISU_UINT64_C(0x8a2dbf14, 2dfcc7ab), 196, 78}, - {GRISU_UINT64_C(0xd7e77a8f, 87daf7fc), 202, 80}, - {GRISU_UINT64_C(0xa8acd7c0, 222311bd), 209, 82}, - {GRISU_UINT64_C(0x83c7088e, 1aab65db), 216, 84}, - {GRISU_UINT64_C(0xcde6fd5e, 09abcf27), 222, 86}, - {GRISU_UINT64_C(0xa0dc75f1, 778e39d6), 229, 88}, - {GRISU_UINT64_C(0xfb587849, 4ace3a5f), 235, 90}, - {GRISU_UINT64_C(0xc45d1df9, 42711d9a), 242, 92}, - {GRISU_UINT64_C(0x9968bf6a, bbe85f20), 249, 94}, - {GRISU_UINT64_C(0xefb3ab16, c59b14a3), 255, 96}, - {GRISU_UINT64_C(0xbb445da9, ca61281f), 262, 98}, - {GRISU_UINT64_C(0x924d692c, a61be758), 269, 100}, - {GRISU_UINT64_C(0xe498f455, c38b997a), 275, 102}, - {GRISU_UINT64_C(0xb2977ee3, 00c50fe7), 282, 104}, - {GRISU_UINT64_C(0x8b865b21, 5899f46d), 289, 106}, - {GRISU_UINT64_C(0xda01ee64, 1a708dea), 295, 108}, - {GRISU_UINT64_C(0xaa51823e, 34a7eedf), 302, 110}, - {GRISU_UINT64_C(0x850fadc0, 9923329e), 309, 112}, - {GRISU_UINT64_C(0xcfe87f7c, ef46ff17), 315, 114}, - {GRISU_UINT64_C(0xa26da399, 9aef774a), 322, 116}, - {GRISU_UINT64_C(0xfdcb4fa0, 02162a63), 328, 118}, - {GRISU_UINT64_C(0xc646d635, 01a1511e), 335, 120}, - {GRISU_UINT64_C(0x9ae75759, 6946075f), 342, 122}, - {GRISU_UINT64_C(0xf209787b, b47d6b85), 348, 124}, - {GRISU_UINT64_C(0xbd176620, a501fc00), 355, 126}, - {GRISU_UINT64_C(0x93ba47c9, 80e98ce0), 362, 128}, - {GRISU_UINT64_C(0xe6d3102a, d96cec1e), 368, 130}, - {GRISU_UINT64_C(0xb454e4a1, 79dd1877), 375, 132}, - {GRISU_UINT64_C(0x8ce2529e, 2734bb1d), 382, 134}, - {GRISU_UINT64_C(0xdc21a117, 1d42645d), 388, 136}, - {GRISU_UINT64_C(0xabfa45da, 0edbde69), 395, 138}, - {GRISU_UINT64_C(0x865b8692, 5b9bc5c2), 402, 140}, - {GRISU_UINT64_C(0xd1ef0244, af2364ff), 408, 142}, - {GRISU_UINT64_C(0xa402b9c5, a8d3a6e7), 415, 144}, - {GRISU_UINT64_C(0x80222122, 6be55a65), 422, 146}, - {GRISU_UINT64_C(0xc83553c5, c8965d3d), 428, 148}, - {GRISU_UINT64_C(0x9c69a972, 84b578d8), 435, 150}, - {GRISU_UINT64_C(0xf46518c2, ef5b8cd1), 441, 152}, - {GRISU_UINT64_C(0xbeeefb58, 4aff8604), 448, 154}, - {GRISU_UINT64_C(0x952ab45c, fa97a0b3), 455, 156}, - {GRISU_UINT64_C(0xe912b9d1, 478ceb17), 461, 158}, - {GRISU_UINT64_C(0xb616a12b, 7fe617aa), 468, 160}, - {GRISU_UINT64_C(0x8e41ade9, fbebc27d), 475, 162}, - {GRISU_UINT64_C(0xde469fbd, 99a05fe3), 481, 164}, - {GRISU_UINT64_C(0xada72ccc, 20054aea), 488, 166}, - {GRISU_UINT64_C(0x87aa9aff, 79042287), 495, 168}, - {GRISU_UINT64_C(0xd3fa922f, 2d1675f2), 501, 170}, - {GRISU_UINT64_C(0xa59bc234, db398c25), 508, 172}, - {GRISU_UINT64_C(0x8161afb9, 4b44f57d), 515, 174}, - {GRISU_UINT64_C(0xca28a291, 859bbf93), 521, 176}, - {GRISU_UINT64_C(0x9defbf01, b061adab), 528, 178}, - {GRISU_UINT64_C(0xf6c69a72, a3989f5c), 534, 180}, - {GRISU_UINT64_C(0xc0cb28a9, 8fcf3c80), 541, 182}, - {GRISU_UINT64_C(0x969eb7c4, 7859e744), 548, 184}, - {GRISU_UINT64_C(0xeb57ff22, fc0c795a), 554, 186}, - {GRISU_UINT64_C(0xb7dcbf53, 54e9bece), 561, 188}, - {GRISU_UINT64_C(0x8fa47579, 1a569d11), 568, 190}, - {GRISU_UINT64_C(0xe070f78d, 3927556b), 574, 192}, - {GRISU_UINT64_C(0xaf584166, 54a6babb), 581, 194}, - {GRISU_UINT64_C(0x88fcf317, f22241e2), 588, 196}, - {GRISU_UINT64_C(0xd60b3bd5, 6a5586f2), 594, 198}, - {GRISU_UINT64_C(0xa738c6be, bb12d16d), 601, 200}, - {GRISU_UINT64_C(0x82a45b45, 0226b39d), 608, 202}, - {GRISU_UINT64_C(0xcc20ce9b, d35c78a5), 614, 204}, - {GRISU_UINT64_C(0x9f79a169, bd203e41), 621, 206}, - {GRISU_UINT64_C(0xf92e0c35, 37826146), 627, 208}, - {GRISU_UINT64_C(0xc2abf989, 935ddbfe), 634, 210}, - {GRISU_UINT64_C(0x98165af3, 7b2153df), 641, 212}, - {GRISU_UINT64_C(0xeda2ee1c, 7064130c), 647, 214}, - {GRISU_UINT64_C(0xb9a74a06, 37ce2ee1), 654, 216}, - {GRISU_UINT64_C(0x910ab1d4, db9914a0), 661, 218}, - {GRISU_UINT64_C(0xe2a0b5dc, 971f303a), 667, 220}, - {GRISU_UINT64_C(0xb10d8e14, 56105dad), 674, 222}, - {GRISU_UINT64_C(0x8a5296ff, e33cc930), 681, 224}, - {GRISU_UINT64_C(0xd8210bef, d30efa5a), 687, 226}, - {GRISU_UINT64_C(0xa8d9d153, 5ce3b396), 694, 228}, - {GRISU_UINT64_C(0x83ea2b89, 2091e44e), 701, 230}, - {GRISU_UINT64_C(0xce1de406, 42e3f4b9), 707, 232}, - {GRISU_UINT64_C(0xa1075a24, e4421731), 714, 234}, - {GRISU_UINT64_C(0xfb9b7cd9, a4a7443c), 720, 236}, - {GRISU_UINT64_C(0xc491798a, 08a2ad4f), 727, 238}, - {GRISU_UINT64_C(0x9991a6f3, d6bf1766), 734, 240}, - {GRISU_UINT64_C(0xeff394dc, ff8a948f), 740, 242}, - {GRISU_UINT64_C(0xbb764c4c, a7a44410), 747, 244}, - {GRISU_UINT64_C(0x92746b9b, e2f8552c), 754, 246}, - {GRISU_UINT64_C(0xe4d5e823, 92a40515), 760, 248}, - {GRISU_UINT64_C(0xb2c71d5b, ca9023f8), 767, 250}, - {GRISU_UINT64_C(0x8bab8eef, b6409c1a), 774, 252}, - {GRISU_UINT64_C(0xda3c0f56, 8cc4f3e9), 780, 254}, - {GRISU_UINT64_C(0xaa7eebfb, 9df9de8e), 787, 256}, - {GRISU_UINT64_C(0x8533285c, 936b35df), 794, 258}, - {GRISU_UINT64_C(0xd01fef10, a657842c), 800, 260}, - {GRISU_UINT64_C(0xa298f2c5, 01f45f43), 807, 262}, - {GRISU_UINT64_C(0xfe0efb53, d30dd4d8), 813, 264}, - {GRISU_UINT64_C(0xc67bb459, 7ce2ce49), 820, 266}, - {GRISU_UINT64_C(0x9b10a4e5, e9913129), 827, 268}, - {GRISU_UINT64_C(0xf24a01a7, 3cf2dcd0), 833, 270}, - {GRISU_UINT64_C(0xbd49d14a, a79dbc82), 840, 272}, - {GRISU_UINT64_C(0x93e1ab82, 52f33b46), 847, 274}, - {GRISU_UINT64_C(0xe7109bfb, a19c0c9d), 853, 276}, - {GRISU_UINT64_C(0xb484f9dc, 9641e9db), 860, 278}, - {GRISU_UINT64_C(0x8d07e334, 55637eb3), 867, 280}, - {GRISU_UINT64_C(0xdc5c5301, c56b75f7), 873, 282}, - {GRISU_UINT64_C(0xac2820d9, 623bf429), 880, 284}, - {GRISU_UINT64_C(0x867f59a9, d4bed6c0), 887, 286}, - {GRISU_UINT64_C(0xd226fc19, 5c6a2f8c), 893, 288}, - {GRISU_UINT64_C(0xa42e74f3, d032f526), 900, 290}, - {GRISU_UINT64_C(0x80444b5e, 7aa7cf85), 907, 292}, - {GRISU_UINT64_C(0xc86ab5c3, 9fa63441), 913, 294}, - {GRISU_UINT64_C(0x9c935e00, d4b9d8d2), 920, 296}, - {GRISU_UINT64_C(0xf4a642e1, 4c6262c9), 926, 298}, - {GRISU_UINT64_C(0xbf21e440, 03acdd2d), 933, 300}, - {GRISU_UINT64_C(0x95527a52, 02df0ccb), 940, 302}, - {GRISU_UINT64_C(0xe950df20, 247c83fd), 946, 304}, - {GRISU_UINT64_C(0xb6472e51, 1c81471e), 953, 306}, - {GRISU_UINT64_C(0x8e679c2f, 5e44ff8f), 960, 308}, - {GRISU_UINT64_C(0xde81e40a, 034bcf50), 966, 310}, - {GRISU_UINT64_C(0xadd57a27, d29339f6), 973, 312}, - {GRISU_UINT64_C(0x87cec76f, 1c830549), 980, 314}, - {GRISU_UINT64_C(0xd433179d, 9c8cb841), 986, 316}, - {GRISU_UINT64_C(0xa5c7ea73, 224deff3), 993, 318}, - {GRISU_UINT64_C(0x81842f29, f2cce376), 1000, 320}, - {GRISU_UINT64_C(0xca5e89b1, 8b602368), 1006, 322}, - {GRISU_UINT64_C(0x9e19db92, b4e31ba9), 1013, 324}, - {GRISU_UINT64_C(0xf7086715, 3aa2db39), 1019, 326}, - {GRISU_UINT64_C(0xc0fe9088, 95cf3b44), 1026, 328}, - {GRISU_UINT64_C(0x96c6e0ea, b509e64d), 1033, 330}, - {GRISU_UINT64_C(0xeb96bf6e, badf77d9), 1039, 332}, - {GRISU_UINT64_C(0xb80dc58e, 81fe95a1), 1046, 334}, - {GRISU_UINT64_C(0x8fcac257, 558ee4e6), 1053, 336}, - {GRISU_UINT64_C(0xe0accfa8, 75af45a8), 1059, 338}, - {GRISU_UINT64_C(0xaf87023b, 9bf0ee6b), 1066, 340}, - {GRISU_UINT64_C(0x892179be, 91d43a44), 1073, 342}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(2) = 7; -// nb elements (2): 326 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(3)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0xe0b62e29, 29aba83c), -1077, -305}, - {GRISU_UINT64_C(0xdb71e914, 32b1a24b), -1067, -302}, - {GRISU_UINT64_C(0xd64d3d9d, b981787d), -1057, -299}, - {GRISU_UINT64_C(0xd1476e2c, 07286faa), -1047, -296}, - {GRISU_UINT64_C(0xcc5fc196, fefd7d0c), -1037, -293}, - {GRISU_UINT64_C(0xc795830d, 75038c1e), -1027, -290}, - {GRISU_UINT64_C(0xc2e801fb, 244576d5), -1017, -287}, - {GRISU_UINT64_C(0xbe5691ef, 416bd60c), -1007, -284}, - {GRISU_UINT64_C(0xb9e08a83, a5e34f08), -997, -281}, - {GRISU_UINT64_C(0xb5854744, 8ffffb2e), -987, -278}, - {GRISU_UINT64_C(0xb1442798, f49ffb4b), -977, -275}, - {GRISU_UINT64_C(0xad1c8eab, 5ee43b67), -967, -272}, - {GRISU_UINT64_C(0xa90de353, 5aaae202), -957, -269}, - {GRISU_UINT64_C(0xa5178fff, 668ae0b6), -947, -266}, - {GRISU_UINT64_C(0xa139029f, 6a239f72), -937, -263}, - {GRISU_UINT64_C(0x9d71ac8f, ada6c9b5), -927, -260}, - {GRISU_UINT64_C(0x99c10284, 4f94e0fb), -917, -257}, - {GRISU_UINT64_C(0x96267c75, 35b763b5), -907, -254}, - {GRISU_UINT64_C(0x92a1958a, 7675175f), -897, -251}, - {GRISU_UINT64_C(0x8f31cc09, 37ae58d3), -887, -248}, - {GRISU_UINT64_C(0x8bd6a141, 006042be), -877, -245}, - {GRISU_UINT64_C(0x888f9979, 7a5e012d), -867, -242}, - {GRISU_UINT64_C(0x855c3be0, a17fcd26), -857, -239}, - {GRISU_UINT64_C(0x823c1279, 5db6ce57), -847, -236}, - {GRISU_UINT64_C(0xfe5d5415, 0b090b03), -838, -233}, - {GRISU_UINT64_C(0xf867241c, 8cc6d4c1), -828, -230}, - {GRISU_UINT64_C(0xf294b943, e17a2bc4), -818, -227}, - {GRISU_UINT64_C(0xece53cec, 4a314ebe), -808, -224}, - {GRISU_UINT64_C(0xe757dd7e, c07426e5), -798, -221}, - {GRISU_UINT64_C(0xe1ebce4d, c7f16dfc), -788, -218}, - {GRISU_UINT64_C(0xdca04777, f541c568), -778, -215}, - {GRISU_UINT64_C(0xd77485cb, 25823ac7), -768, -212}, - {GRISU_UINT64_C(0xd267caa8, 62a12d67), -758, -209}, - {GRISU_UINT64_C(0xcd795be8, 70516656), -748, -206}, - {GRISU_UINT64_C(0xc8a883c0, fdaf7df0), -738, -203}, - {GRISU_UINT64_C(0xc3f490aa, 77bd60fd), -728, -200}, - {GRISU_UINT64_C(0xbf5cd546, 78eef0b7), -718, -197}, - {GRISU_UINT64_C(0xbae0a846, d2195713), -708, -194}, - {GRISU_UINT64_C(0xb67f6455, 292cbf08), -698, -191}, - {GRISU_UINT64_C(0xb23867fb, 2a35b28e), -688, -188}, - {GRISU_UINT64_C(0xae0b158b, 4738705f), -678, -185}, - {GRISU_UINT64_C(0xa9f6d30a, 038d1dbc), -668, -182}, - {GRISU_UINT64_C(0xa5fb0a17, c777cf0a), -658, -179}, - {GRISU_UINT64_C(0xa21727db, 38cb0030), -648, -176}, - {GRISU_UINT64_C(0x9e4a9cec, 15763e2f), -638, -173}, - {GRISU_UINT64_C(0x9a94dd3e, 8cf578ba), -628, -170}, - {GRISU_UINT64_C(0x96f5600f, 15a7b7e5), -618, -167}, - {GRISU_UINT64_C(0x936b9fce, bb25c996), -608, -164}, - {GRISU_UINT64_C(0x8ff71a0f, e2c2e6dc), -598, -161}, - {GRISU_UINT64_C(0x8c974f73, 83725573), -588, -158}, - {GRISU_UINT64_C(0x894bc396, ce5da772), -578, -155}, - {GRISU_UINT64_C(0x8613fd01, 45877586), -568, -152}, - {GRISU_UINT64_C(0x82ef8513, 3de648c5), -558, -149}, - {GRISU_UINT64_C(0xffbbcfe9, 94e5c620), -549, -146}, - {GRISU_UINT64_C(0xf9bd690a, 1b68637b), -539, -143}, - {GRISU_UINT64_C(0xf3e2f893, dec3f126), -529, -140}, - {GRISU_UINT64_C(0xee2ba6c0, 678b597f), -519, -137}, - {GRISU_UINT64_C(0xe896a0d7, e51e1566), -509, -134}, - {GRISU_UINT64_C(0xe3231912, d5bf60e6), -499, -131}, - {GRISU_UINT64_C(0xddd0467c, 64bce4a1), -489, -128}, - {GRISU_UINT64_C(0xd89d64d5, 7a607745), -479, -125}, - {GRISU_UINT64_C(0xd389b478, 79823479), -469, -122}, - {GRISU_UINT64_C(0xce947a3d, a6a9273e), -459, -119}, - {GRISU_UINT64_C(0xc9bcff60, 34c13053), -449, -116}, - {GRISU_UINT64_C(0xc5029163, f384a931), -439, -113}, - {GRISU_UINT64_C(0xc06481fb, 9bcf8d3a), -429, -110}, - {GRISU_UINT64_C(0xbbe226ef, b628afeb), -419, -107}, - {GRISU_UINT64_C(0xb77ada06, 17e3bbcb), -409, -104}, - {GRISU_UINT64_C(0xb32df8e9, f3546564), -399, -101}, - {GRISU_UINT64_C(0xaefae514, 77a06b04), -389, -98}, - {GRISU_UINT64_C(0xaae103b5, fcd2a882), -379, -95}, - {GRISU_UINT64_C(0xa6dfbd9f, b8e5b88f), -369, -92}, - {GRISU_UINT64_C(0xa2f67f2d, fa90563b), -359, -89}, - {GRISU_UINT64_C(0x9f24b832, e6b0f436), -349, -86}, - {GRISU_UINT64_C(0x9b69dbe1, b548ce7d), -339, -83}, - {GRISU_UINT64_C(0x97c560ba, 6b0919a6), -329, -80}, - {GRISU_UINT64_C(0x9436c076, 0c86e30c), -319, -77}, - {GRISU_UINT64_C(0x90bd77f3, 483bb9ba), -309, -74}, - {GRISU_UINT64_C(0x8d590723, 948a535f), -299, -71}, - {GRISU_UINT64_C(0x8a08f0f8, bf0f156b), -289, -68}, - {GRISU_UINT64_C(0x86ccbb52, ea94baeb), -279, -65}, - {GRISU_UINT64_C(0x83a3eeee, f9153e89), -269, -62}, - {GRISU_UINT64_C(0x808e1755, 5f3ebf12), -259, -59}, - {GRISU_UINT64_C(0xfb158592, be068d2f), -250, -56}, - {GRISU_UINT64_C(0xf5330471, 4d9265e0), -240, -53}, - {GRISU_UINT64_C(0xef73d256, a5c0f77d), -230, -50}, - {GRISU_UINT64_C(0xe9d71b68, 9dde71b0), -220, -47}, - {GRISU_UINT64_C(0xe45c10c4, 2a2b3b06), -210, -44}, - {GRISU_UINT64_C(0xdf01e85f, 912e37a3), -200, -41}, - {GRISU_UINT64_C(0xd9c7dced, 53c72256), -190, -38}, - {GRISU_UINT64_C(0xd4ad2dbf, c3d07788), -180, -35}, - {GRISU_UINT64_C(0xcfb11ead, 453994ba), -170, -32}, - {GRISU_UINT64_C(0xcad2f7f5, 359a3b3e), -160, -29}, - {GRISU_UINT64_C(0xc6120625, 76589ddb), -150, -26}, - {GRISU_UINT64_C(0xc16d9a00, 95928a27), -140, -23}, - {GRISU_UINT64_C(0xbce50864, 92111aeb), -130, -20}, - {GRISU_UINT64_C(0xb877aa32, 36a4b449), -120, -17}, - {GRISU_UINT64_C(0xb424dc35, 095cd80f), -110, -14}, - {GRISU_UINT64_C(0xafebff0b, cb24aaff), -100, -11}, - {GRISU_UINT64_C(0xabcc7711, 8461cefd), -90, -8}, - {GRISU_UINT64_C(0xa7c5ac47, 1b478423), -80, -5}, - {GRISU_UINT64_C(0xa3d70a3d, 70a3d70a), -70, -2}, - {GRISU_UINT64_C(0xa0000000, 00000000), -60, 1}, - {GRISU_UINT64_C(0x9c400000, 00000000), -50, 4}, - {GRISU_UINT64_C(0x98968000, 00000000), -40, 7}, - {GRISU_UINT64_C(0x9502f900, 00000000), -30, 10}, - {GRISU_UINT64_C(0x9184e72a, 00000000), -20, 13}, - {GRISU_UINT64_C(0x8e1bc9bf, 04000000), -10, 16}, - {GRISU_UINT64_C(0x8ac72304, 89e80000), 0, 19}, - {GRISU_UINT64_C(0x87867832, 6eac9000), 10, 22}, - {GRISU_UINT64_C(0x84595161, 401484a0), 20, 25}, - {GRISU_UINT64_C(0x813f3978, f8940984), 30, 28}, - {GRISU_UINT64_C(0xfc6f7c40, 45812296), 39, 31}, - {GRISU_UINT64_C(0xf684df56, c3e01bc7), 49, 34}, - {GRISU_UINT64_C(0xf0bdc21a, bb48db20), 59, 37}, - {GRISU_UINT64_C(0xeb194f8e, 1ae525fd), 69, 40}, - {GRISU_UINT64_C(0xe596b7b0, c643c719), 79, 43}, - {GRISU_UINT64_C(0xe0352f62, a19e306f), 89, 46}, - {GRISU_UINT64_C(0xdaf3f046, 51d47b4c), 99, 49}, - {GRISU_UINT64_C(0xd5d238a4, abe98068), 109, 52}, - {GRISU_UINT64_C(0xd0cf4b50, cfe20766), 119, 55}, - {GRISU_UINT64_C(0xcbea6f8c, eb02bb3a), 129, 58}, - {GRISU_UINT64_C(0xc722f0ef, 9d80aad6), 139, 61}, - {GRISU_UINT64_C(0xc2781f49, ffcfa6d5), 149, 64}, - {GRISU_UINT64_C(0xbde94e8e, 43d0c8ec), 159, 67}, - {GRISU_UINT64_C(0xb975d6b6, ee39e437), 169, 70}, - {GRISU_UINT64_C(0xb51d13ae, a4a488dd), 179, 73}, - {GRISU_UINT64_C(0xb0de6538, 8cc8ada8), 189, 76}, - {GRISU_UINT64_C(0xacb92ed9, 397bf996), 199, 79}, - {GRISU_UINT64_C(0xa8acd7c0, 222311bd), 209, 82}, - {GRISU_UINT64_C(0xa4b8cab1, a1563f52), 219, 85}, - {GRISU_UINT64_C(0xa0dc75f1, 778e39d6), 229, 88}, - {GRISU_UINT64_C(0x9d174b2d, cec0e47b), 239, 91}, - {GRISU_UINT64_C(0x9968bf6a, bbe85f20), 249, 94}, - {GRISU_UINT64_C(0x95d04aee, 3b80ece6), 259, 97}, - {GRISU_UINT64_C(0x924d692c, a61be758), 269, 100}, - {GRISU_UINT64_C(0x8edf98b5, 9a373fec), 279, 103}, - {GRISU_UINT64_C(0x8b865b21, 5899f46d), 289, 106}, - {GRISU_UINT64_C(0x884134fe, 908658b2), 299, 109}, - {GRISU_UINT64_C(0x850fadc0, 9923329e), 309, 112}, - {GRISU_UINT64_C(0x81f14fae, 158c5f6e), 319, 115}, - {GRISU_UINT64_C(0xfdcb4fa0, 02162a63), 328, 118}, - {GRISU_UINT64_C(0xf7d88bc2, 4209a565), 338, 121}, - {GRISU_UINT64_C(0xf209787b, b47d6b85), 348, 124}, - {GRISU_UINT64_C(0xec5d3fa8, ce427b00), 358, 127}, - {GRISU_UINT64_C(0xe6d3102a, d96cec1e), 368, 130}, - {GRISU_UINT64_C(0xe16a1dc9, d8545e95), 378, 133}, - {GRISU_UINT64_C(0xdc21a117, 1d42645d), 388, 136}, - {GRISU_UINT64_C(0xd6f8d750, 9292d603), 398, 139}, - {GRISU_UINT64_C(0xd1ef0244, af2364ff), 408, 142}, - {GRISU_UINT64_C(0xcd036837, 130890a1), 418, 145}, - {GRISU_UINT64_C(0xc83553c5, c8965d3d), 428, 148}, - {GRISU_UINT64_C(0xc38413cf, 25e2d70e), 438, 151}, - {GRISU_UINT64_C(0xbeeefb58, 4aff8604), 448, 154}, - {GRISU_UINT64_C(0xba756174, 393d88e0), 458, 157}, - {GRISU_UINT64_C(0xb616a12b, 7fe617aa), 468, 160}, - {GRISU_UINT64_C(0xb1d21964, 7ae6b31c), 478, 163}, - {GRISU_UINT64_C(0xada72ccc, 20054aea), 488, 166}, - {GRISU_UINT64_C(0xa99541bf, 57452b28), 498, 169}, - {GRISU_UINT64_C(0xa59bc234, db398c25), 508, 172}, - {GRISU_UINT64_C(0xa1ba1ba7, 9e1632dc), 518, 175}, - {GRISU_UINT64_C(0x9defbf01, b061adab), 528, 178}, - {GRISU_UINT64_C(0x9a3c2087, a63f6399), 538, 181}, - {GRISU_UINT64_C(0x969eb7c4, 7859e744), 548, 184}, - {GRISU_UINT64_C(0x9316ff75, dd87cbd8), 558, 187}, - {GRISU_UINT64_C(0x8fa47579, 1a569d11), 568, 190}, - {GRISU_UINT64_C(0x8c469ab8, 43b89563), 578, 193}, - {GRISU_UINT64_C(0x88fcf317, f22241e2), 588, 196}, - {GRISU_UINT64_C(0x85c70565, 62757457), 598, 199}, - {GRISU_UINT64_C(0x82a45b45, 0226b39d), 608, 202}, - {GRISU_UINT64_C(0xff290242, c83396ce), 617, 205}, - {GRISU_UINT64_C(0xf92e0c35, 37826146), 627, 208}, - {GRISU_UINT64_C(0xf356f7eb, f83552fe), 637, 211}, - {GRISU_UINT64_C(0xeda2ee1c, 7064130c), 647, 214}, - {GRISU_UINT64_C(0xe8111c87, c5c1ba9a), 657, 217}, - {GRISU_UINT64_C(0xe2a0b5dc, 971f303a), 667, 220}, - {GRISU_UINT64_C(0xdd50f199, 6b947519), 677, 223}, - {GRISU_UINT64_C(0xd8210bef, d30efa5a), 687, 226}, - {GRISU_UINT64_C(0xd31045a8, 341ca07c), 697, 229}, - {GRISU_UINT64_C(0xce1de406, 42e3f4b9), 707, 232}, - {GRISU_UINT64_C(0xc94930ae, 1d529cfd), 717, 235}, - {GRISU_UINT64_C(0xc491798a, 08a2ad4f), 727, 238}, - {GRISU_UINT64_C(0xbff610b0, cc6edd3f), 737, 241}, - {GRISU_UINT64_C(0xbb764c4c, a7a44410), 747, 244}, - {GRISU_UINT64_C(0xb7118682, dbb66a77), 757, 247}, - {GRISU_UINT64_C(0xb2c71d5b, ca9023f8), 767, 250}, - {GRISU_UINT64_C(0xae9672ab, a3d0c321), 777, 253}, - {GRISU_UINT64_C(0xaa7eebfb, 9df9de8e), 787, 256}, - {GRISU_UINT64_C(0xa67ff273, b8460357), 797, 259}, - {GRISU_UINT64_C(0xa298f2c5, 01f45f43), 807, 262}, - {GRISU_UINT64_C(0x9ec95d14, 63e8a507), 817, 265}, - {GRISU_UINT64_C(0x9b10a4e5, e9913129), 827, 268}, - {GRISU_UINT64_C(0x976e4108, 8617ca02), 837, 271}, - {GRISU_UINT64_C(0x93e1ab82, 52f33b46), 847, 274}, - {GRISU_UINT64_C(0x906a617d, 450187e2), 857, 277}, - {GRISU_UINT64_C(0x8d07e334, 55637eb3), 867, 280}, - {GRISU_UINT64_C(0x89b9b3e1, 1b6329bb), 877, 283}, - {GRISU_UINT64_C(0x867f59a9, d4bed6c0), 887, 286}, - {GRISU_UINT64_C(0x83585d8f, d9c25db8), 897, 289}, - {GRISU_UINT64_C(0x80444b5e, 7aa7cf85), 907, 292}, - {GRISU_UINT64_C(0xfa856334, 878fc151), 916, 295}, - {GRISU_UINT64_C(0xf4a642e1, 4c6262c9), 926, 298}, - {GRISU_UINT64_C(0xeeea5d50, 04981478), 936, 301}, - {GRISU_UINT64_C(0xe950df20, 247c83fd), 946, 304}, - {GRISU_UINT64_C(0xe3d8f9e5, 63a198e5), 956, 307}, - {GRISU_UINT64_C(0xde81e40a, 034bcf50), 966, 310}, - {GRISU_UINT64_C(0xd94ad8b1, c7380874), 976, 313}, - {GRISU_UINT64_C(0xd433179d, 9c8cb841), 986, 316}, - {GRISU_UINT64_C(0xcf39e50f, eae16bf0), 996, 319}, - {GRISU_UINT64_C(0xca5e89b1, 8b602368), 1006, 322}, - {GRISU_UINT64_C(0xc5a05277, 621be294), 1016, 325}, - {GRISU_UINT64_C(0xc0fe9088, 95cf3b44), 1026, 328}, - {GRISU_UINT64_C(0xbc789925, 624c5fe1), 1036, 331}, - {GRISU_UINT64_C(0xb80dc58e, 81fe95a1), 1046, 334}, - {GRISU_UINT64_C(0xb3bd72ed, 2af29e20), 1056, 337}, - {GRISU_UINT64_C(0xaf87023b, 9bf0ee6b), 1066, 340}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(3) = 10; -// nb elements (3): 217 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(4)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0x8c71dcd9, ba0b4926), -1073, -304}, - {GRISU_UINT64_C(0xab70fe17, c79ac6ca), -1060, -300}, - {GRISU_UINT64_C(0xd1476e2c, 07286faa), -1047, -296}, - {GRISU_UINT64_C(0xff77b1fc, bebcdc4f), -1034, -292}, - {GRISU_UINT64_C(0x9becce62, 836ac577), -1020, -288}, - {GRISU_UINT64_C(0xbe5691ef, 416bd60c), -1007, -284}, - {GRISU_UINT64_C(0xe858ad24, 8f5c22ca), -994, -280}, - {GRISU_UINT64_C(0x8dd01fad, 907ffc3c), -980, -276}, - {GRISU_UINT64_C(0xad1c8eab, 5ee43b67), -967, -272}, - {GRISU_UINT64_C(0xd3515c28, 31559a83), -954, -268}, - {GRISU_UINT64_C(0x80fa687f, 881c7f8e), -940, -264}, - {GRISU_UINT64_C(0x9d71ac8f, ada6c9b5), -927, -260}, - {GRISU_UINT64_C(0xc0314325, 637a193a), -914, -256}, - {GRISU_UINT64_C(0xea9c2277, 23ee8bcb), -901, -252}, - {GRISU_UINT64_C(0x8f31cc09, 37ae58d3), -887, -248}, - {GRISU_UINT64_C(0xaecc4991, 4078536d), -874, -244}, - {GRISU_UINT64_C(0xd5605fcd, cf32e1d7), -861, -240}, - {GRISU_UINT64_C(0x823c1279, 5db6ce57), -847, -236}, - {GRISU_UINT64_C(0x9efa548d, 26e5a6e2), -834, -232}, - {GRISU_UINT64_C(0xc2109436, 4dfb5637), -821, -228}, - {GRISU_UINT64_C(0xece53cec, 4a314ebe), -808, -224}, - {GRISU_UINT64_C(0x9096ea6f, 3848984f), -794, -220}, - {GRISU_UINT64_C(0xb080392c, c4349ded), -781, -216}, - {GRISU_UINT64_C(0xd77485cb, 25823ac7), -768, -212}, - {GRISU_UINT64_C(0x8380dea9, 3da4bc60), -754, -208}, - {GRISU_UINT64_C(0xa086cfcd, 97bf97f4), -741, -204}, - {GRISU_UINT64_C(0xc3f490aa, 77bd60fd), -728, -200}, - {GRISU_UINT64_C(0xef340a98, 172aace5), -715, -196}, - {GRISU_UINT64_C(0x91ff8377, 5423cc06), -701, -192}, - {GRISU_UINT64_C(0xb23867fb, 2a35b28e), -688, -188}, - {GRISU_UINT64_C(0xd98ddaee, 19068c76), -675, -184}, - {GRISU_UINT64_C(0x84c8d4df, d2c63f3b), -661, -180}, - {GRISU_UINT64_C(0xa21727db, 38cb0030), -648, -176}, - {GRISU_UINT64_C(0xc5dd4427, 1ad3cdba), -635, -172}, - {GRISU_UINT64_C(0xf18899b1, bc3f8ca2), -622, -168}, - {GRISU_UINT64_C(0x936b9fce, bb25c996), -608, -164}, - {GRISU_UINT64_C(0xb3f4e093, db73a093), -595, -160}, - {GRISU_UINT64_C(0xdbac6c24, 7d62a584), -582, -156}, - {GRISU_UINT64_C(0x8613fd01, 45877586), -568, -152}, - {GRISU_UINT64_C(0xa3ab6658, 0d5fdaf6), -555, -148}, - {GRISU_UINT64_C(0xc7caba6e, 7c5382c9), -542, -144}, - {GRISU_UINT64_C(0xf3e2f893, dec3f126), -529, -140}, - {GRISU_UINT64_C(0x94db4838, 40b717f0), -515, -136}, - {GRISU_UINT64_C(0xb5b5ada8, aaff80b8), -502, -132}, - {GRISU_UINT64_C(0xddd0467c, 64bce4a1), -489, -128}, - {GRISU_UINT64_C(0x87625f05, 6c7c4a8b), -475, -124}, - {GRISU_UINT64_C(0xa54394fe, 1eedb8ff), -462, -120}, - {GRISU_UINT64_C(0xc9bcff60, 34c13053), -449, -116}, - {GRISU_UINT64_C(0xf64335bc, f065d37d), -436, -112}, - {GRISU_UINT64_C(0x964e858c, 91ba2655), -422, -108}, - {GRISU_UINT64_C(0xb77ada06, 17e3bbcb), -409, -104}, - {GRISU_UINT64_C(0xdff97724, 70297ebd), -396, -100}, - {GRISU_UINT64_C(0x88b402f7, fd75539b), -382, -96}, - {GRISU_UINT64_C(0xa6dfbd9f, b8e5b88f), -369, -92}, - {GRISU_UINT64_C(0xcbb41ef9, 79346bca), -356, -88}, - {GRISU_UINT64_C(0xf8a95fcf, 88747d94), -343, -84}, - {GRISU_UINT64_C(0x97c560ba, 6b0919a6), -329, -80}, - {GRISU_UINT64_C(0xb9447093, 8fa89bcf), -316, -76}, - {GRISU_UINT64_C(0xe2280b6c, 20dd5232), -303, -72}, - {GRISU_UINT64_C(0x8a08f0f8, bf0f156b), -289, -68}, - {GRISU_UINT64_C(0xa87fea27, a539e9a5), -276, -64}, - {GRISU_UINT64_C(0xcdb02555, 653131b6), -263, -60}, - {GRISU_UINT64_C(0xfb158592, be068d2f), -250, -56}, - {GRISU_UINT64_C(0x993fe2c6, d07b7fac), -236, -52}, - {GRISU_UINT64_C(0xbb127c53, b17ec159), -223, -48}, - {GRISU_UINT64_C(0xe45c10c4, 2a2b3b06), -210, -44}, - {GRISU_UINT64_C(0x8b61313b, babce2c6), -196, -40}, - {GRISU_UINT64_C(0xaa242499, 697392d3), -183, -36}, - {GRISU_UINT64_C(0xcfb11ead, 453994ba), -170, -32}, - {GRISU_UINT64_C(0xfd87b5f2, 8300ca0e), -157, -28}, - {GRISU_UINT64_C(0x9abe14cd, 44753b53), -143, -24}, - {GRISU_UINT64_C(0xbce50864, 92111aeb), -130, -20}, - {GRISU_UINT64_C(0xe69594be, c44de15b), -117, -16}, - {GRISU_UINT64_C(0x8cbccc09, 6f5088cc), -103, -12}, - {GRISU_UINT64_C(0xabcc7711, 8461cefd), -90, -8}, - {GRISU_UINT64_C(0xd1b71758, e219652c), -77, -4}, - {GRISU_UINT64_C(0x80000000, 00000000), -63, 0}, - {GRISU_UINT64_C(0x9c400000, 00000000), -50, 4}, - {GRISU_UINT64_C(0xbebc2000, 00000000), -37, 8}, - {GRISU_UINT64_C(0xe8d4a510, 00000000), -24, 12}, - {GRISU_UINT64_C(0x8e1bc9bf, 04000000), -10, 16}, - {GRISU_UINT64_C(0xad78ebc5, ac620000), 3, 20}, - {GRISU_UINT64_C(0xd3c21bce, cceda100), 16, 24}, - {GRISU_UINT64_C(0x813f3978, f8940984), 30, 28}, - {GRISU_UINT64_C(0x9dc5ada8, 2b70b59e), 43, 32}, - {GRISU_UINT64_C(0xc097ce7b, c90715b3), 56, 36}, - {GRISU_UINT64_C(0xeb194f8e, 1ae525fd), 69, 40}, - {GRISU_UINT64_C(0x8f7e32ce, 7bea5c70), 83, 44}, - {GRISU_UINT64_C(0xaf298d05, 0e4395d7), 96, 48}, - {GRISU_UINT64_C(0xd5d238a4, abe98068), 109, 52}, - {GRISU_UINT64_C(0x82818f12, 81ed44a0), 123, 56}, - {GRISU_UINT64_C(0x9f4f2726, 179a2245), 136, 60}, - {GRISU_UINT64_C(0xc2781f49, ffcfa6d5), 149, 64}, - {GRISU_UINT64_C(0xed63a231, d4c4fb27), 162, 68}, - {GRISU_UINT64_C(0x90e40fbe, ea1d3a4b), 176, 72}, - {GRISU_UINT64_C(0xb0de6538, 8cc8ada8), 189, 76}, - {GRISU_UINT64_C(0xd7e77a8f, 87daf7fc), 202, 80}, - {GRISU_UINT64_C(0x83c7088e, 1aab65db), 216, 84}, - {GRISU_UINT64_C(0xa0dc75f1, 778e39d6), 229, 88}, - {GRISU_UINT64_C(0xc45d1df9, 42711d9a), 242, 92}, - {GRISU_UINT64_C(0xefb3ab16, c59b14a3), 255, 96}, - {GRISU_UINT64_C(0x924d692c, a61be758), 269, 100}, - {GRISU_UINT64_C(0xb2977ee3, 00c50fe7), 282, 104}, - {GRISU_UINT64_C(0xda01ee64, 1a708dea), 295, 108}, - {GRISU_UINT64_C(0x850fadc0, 9923329e), 309, 112}, - {GRISU_UINT64_C(0xa26da399, 9aef774a), 322, 116}, - {GRISU_UINT64_C(0xc646d635, 01a1511e), 335, 120}, - {GRISU_UINT64_C(0xf209787b, b47d6b85), 348, 124}, - {GRISU_UINT64_C(0x93ba47c9, 80e98ce0), 362, 128}, - {GRISU_UINT64_C(0xb454e4a1, 79dd1877), 375, 132}, - {GRISU_UINT64_C(0xdc21a117, 1d42645d), 388, 136}, - {GRISU_UINT64_C(0x865b8692, 5b9bc5c2), 402, 140}, - {GRISU_UINT64_C(0xa402b9c5, a8d3a6e7), 415, 144}, - {GRISU_UINT64_C(0xc83553c5, c8965d3d), 428, 148}, - {GRISU_UINT64_C(0xf46518c2, ef5b8cd1), 441, 152}, - {GRISU_UINT64_C(0x952ab45c, fa97a0b3), 455, 156}, - {GRISU_UINT64_C(0xb616a12b, 7fe617aa), 468, 160}, - {GRISU_UINT64_C(0xde469fbd, 99a05fe3), 481, 164}, - {GRISU_UINT64_C(0x87aa9aff, 79042287), 495, 168}, - {GRISU_UINT64_C(0xa59bc234, db398c25), 508, 172}, - {GRISU_UINT64_C(0xca28a291, 859bbf93), 521, 176}, - {GRISU_UINT64_C(0xf6c69a72, a3989f5c), 534, 180}, - {GRISU_UINT64_C(0x969eb7c4, 7859e744), 548, 184}, - {GRISU_UINT64_C(0xb7dcbf53, 54e9bece), 561, 188}, - {GRISU_UINT64_C(0xe070f78d, 3927556b), 574, 192}, - {GRISU_UINT64_C(0x88fcf317, f22241e2), 588, 196}, - {GRISU_UINT64_C(0xa738c6be, bb12d16d), 601, 200}, - {GRISU_UINT64_C(0xcc20ce9b, d35c78a5), 614, 204}, - {GRISU_UINT64_C(0xf92e0c35, 37826146), 627, 208}, - {GRISU_UINT64_C(0x98165af3, 7b2153df), 641, 212}, - {GRISU_UINT64_C(0xb9a74a06, 37ce2ee1), 654, 216}, - {GRISU_UINT64_C(0xe2a0b5dc, 971f303a), 667, 220}, - {GRISU_UINT64_C(0x8a5296ff, e33cc930), 681, 224}, - {GRISU_UINT64_C(0xa8d9d153, 5ce3b396), 694, 228}, - {GRISU_UINT64_C(0xce1de406, 42e3f4b9), 707, 232}, - {GRISU_UINT64_C(0xfb9b7cd9, a4a7443c), 720, 236}, - {GRISU_UINT64_C(0x9991a6f3, d6bf1766), 734, 240}, - {GRISU_UINT64_C(0xbb764c4c, a7a44410), 747, 244}, - {GRISU_UINT64_C(0xe4d5e823, 92a40515), 760, 248}, - {GRISU_UINT64_C(0x8bab8eef, b6409c1a), 774, 252}, - {GRISU_UINT64_C(0xaa7eebfb, 9df9de8e), 787, 256}, - {GRISU_UINT64_C(0xd01fef10, a657842c), 800, 260}, - {GRISU_UINT64_C(0xfe0efb53, d30dd4d8), 813, 264}, - {GRISU_UINT64_C(0x9b10a4e5, e9913129), 827, 268}, - {GRISU_UINT64_C(0xbd49d14a, a79dbc82), 840, 272}, - {GRISU_UINT64_C(0xe7109bfb, a19c0c9d), 853, 276}, - {GRISU_UINT64_C(0x8d07e334, 55637eb3), 867, 280}, - {GRISU_UINT64_C(0xac2820d9, 623bf429), 880, 284}, - {GRISU_UINT64_C(0xd226fc19, 5c6a2f8c), 893, 288}, - {GRISU_UINT64_C(0x80444b5e, 7aa7cf85), 907, 292}, - {GRISU_UINT64_C(0x9c935e00, d4b9d8d2), 920, 296}, - {GRISU_UINT64_C(0xbf21e440, 03acdd2d), 933, 300}, - {GRISU_UINT64_C(0xe950df20, 247c83fd), 946, 304}, - {GRISU_UINT64_C(0x8e679c2f, 5e44ff8f), 960, 308}, - {GRISU_UINT64_C(0xadd57a27, d29339f6), 973, 312}, - {GRISU_UINT64_C(0xd433179d, 9c8cb841), 986, 316}, - {GRISU_UINT64_C(0x81842f29, f2cce376), 1000, 320}, - {GRISU_UINT64_C(0x9e19db92, b4e31ba9), 1013, 324}, - {GRISU_UINT64_C(0xc0fe9088, 95cf3b44), 1026, 328}, - {GRISU_UINT64_C(0xeb96bf6e, badf77d9), 1039, 332}, - {GRISU_UINT64_C(0x8fcac257, 558ee4e6), 1053, 336}, - {GRISU_UINT64_C(0xaf87023b, 9bf0ee6b), 1066, 340}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(4) = 14; -// nb elements (4): 163 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(5)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0xaf8e5410, 288e1b6f), -1070, -303}, - {GRISU_UINT64_C(0x85f04682, 93f0eb4e), -1053, -298}, - {GRISU_UINT64_C(0xcc5fc196, fefd7d0c), -1037, -293}, - {GRISU_UINT64_C(0x9becce62, 836ac577), -1020, -288}, - {GRISU_UINT64_C(0xedec366b, 11c6cb8f), -1004, -283}, - {GRISU_UINT64_C(0xb5854744, 8ffffb2e), -987, -278}, - {GRISU_UINT64_C(0x8a7d3eef, 7f1cfc52), -970, -273}, - {GRISU_UINT64_C(0xd3515c28, 31559a83), -954, -268}, - {GRISU_UINT64_C(0xa139029f, 6a239f72), -937, -263}, - {GRISU_UINT64_C(0xf6019da0, 7f549b2b), -921, -258}, - {GRISU_UINT64_C(0xbbb01b92, 83253ca3), -904, -253}, - {GRISU_UINT64_C(0x8f31cc09, 37ae58d3), -887, -248}, - {GRISU_UINT64_C(0xda7f5bf5, 90966849), -871, -243}, - {GRISU_UINT64_C(0xa6b34ad8, c9dfc070), -854, -238}, - {GRISU_UINT64_C(0xfe5d5415, 0b090b03), -838, -233}, - {GRISU_UINT64_C(0xc2109436, 4dfb5637), -821, -228}, - {GRISU_UINT64_C(0x940f4613, ae5ed137), -804, -223}, - {GRISU_UINT64_C(0xe1ebce4d, c7f16dfc), -788, -218}, - {GRISU_UINT64_C(0xac5d37d5, b79b6239), -771, -213}, - {GRISU_UINT64_C(0x8380dea9, 3da4bc60), -754, -208}, - {GRISU_UINT64_C(0xc8a883c0, fdaf7df0), -738, -203}, - {GRISU_UINT64_C(0x99171105, 2d8bf3c5), -721, -198}, - {GRISU_UINT64_C(0xe998d258, 869facd7), -705, -193}, - {GRISU_UINT64_C(0xb23867fb, 2a35b28e), -688, -188}, - {GRISU_UINT64_C(0x87f8a8d4, cfa417ca), -671, -183}, - {GRISU_UINT64_C(0xcf79cc9d, b955c2cc), -655, -178}, - {GRISU_UINT64_C(0x9e4a9cec, 15763e2f), -638, -173}, - {GRISU_UINT64_C(0xf18899b1, bc3f8ca2), -622, -168}, - {GRISU_UINT64_C(0xb84687c2, 69ef3bfb), -605, -163}, - {GRISU_UINT64_C(0x8c974f73, 83725573), -588, -158}, - {GRISU_UINT64_C(0xd686619b, a27255a3), -572, -153}, - {GRISU_UINT64_C(0xa3ab6658, 0d5fdaf6), -555, -148}, - {GRISU_UINT64_C(0xf9bd690a, 1b68637b), -539, -143}, - {GRISU_UINT64_C(0xbe895233, 86091466), -522, -138}, - {GRISU_UINT64_C(0x915e2486, ef32cd60), -505, -133}, - {GRISU_UINT64_C(0xddd0467c, 64bce4a1), -489, -128}, - {GRISU_UINT64_C(0xa93af6c6, c79b5d2e), -472, -123}, - {GRISU_UINT64_C(0x811ccc66, 8829b887), -455, -118}, - {GRISU_UINT64_C(0xc5029163, f384a931), -439, -113}, - {GRISU_UINT64_C(0x964e858c, 91ba2655), -422, -108}, - {GRISU_UINT64_C(0xe5599087, 9ddcaabe), -406, -103}, - {GRISU_UINT64_C(0xaefae514, 77a06b04), -389, -98}, - {GRISU_UINT64_C(0x857fcae6, 2d8493a5), -372, -93}, - {GRISU_UINT64_C(0xcbb41ef9, 79346bca), -356, -88}, - {GRISU_UINT64_C(0x9b69dbe1, b548ce7d), -339, -83}, - {GRISU_UINT64_C(0xed246723, 473e3813), -323, -78}, - {GRISU_UINT64_C(0xb4ecd5f0, 1a4aa828), -306, -73}, - {GRISU_UINT64_C(0x8a08f0f8, bf0f156b), -289, -68}, - {GRISU_UINT64_C(0xd29fe4b1, 8e88640f), -273, -63}, - {GRISU_UINT64_C(0xa0b19d2a, b70e6ed6), -256, -58}, - {GRISU_UINT64_C(0xf5330471, 4d9265e0), -240, -53}, - {GRISU_UINT64_C(0xbb127c53, b17ec159), -223, -48}, - {GRISU_UINT64_C(0x8eb98a7a, 9a5b04e3), -206, -43}, - {GRISU_UINT64_C(0xd9c7dced, 53c72256), -190, -38}, - {GRISU_UINT64_C(0xa6274bbd, d0fadd62), -173, -33}, - {GRISU_UINT64_C(0xfd87b5f2, 8300ca0e), -157, -28}, - {GRISU_UINT64_C(0xc16d9a00, 95928a27), -140, -23}, - {GRISU_UINT64_C(0x9392ee8e, 921d5d07), -123, -18}, - {GRISU_UINT64_C(0xe12e1342, 4bb40e13), -107, -13}, - {GRISU_UINT64_C(0xabcc7711, 8461cefd), -90, -8}, - {GRISU_UINT64_C(0x83126e97, 8d4fdf3b), -73, -3}, - {GRISU_UINT64_C(0xc8000000, 00000000), -57, 2}, - {GRISU_UINT64_C(0x98968000, 00000000), -40, 7}, - {GRISU_UINT64_C(0xe8d4a510, 00000000), -24, 12}, - {GRISU_UINT64_C(0xb1a2bc2e, c5000000), -7, 17}, - {GRISU_UINT64_C(0x87867832, 6eac9000), 10, 22}, - {GRISU_UINT64_C(0xcecb8f27, f4200f3a), 26, 27}, - {GRISU_UINT64_C(0x9dc5ada8, 2b70b59e), 43, 32}, - {GRISU_UINT64_C(0xf0bdc21a, bb48db20), 59, 37}, - {GRISU_UINT64_C(0xb7abc627, 050305ae), 76, 42}, - {GRISU_UINT64_C(0x8c213d9d, a502de45), 93, 47}, - {GRISU_UINT64_C(0xd5d238a4, abe98068), 109, 52}, - {GRISU_UINT64_C(0xa321f2d7, 226895c8), 126, 57}, - {GRISU_UINT64_C(0xf8ebad2b, 84e0d58c), 142, 62}, - {GRISU_UINT64_C(0xbde94e8e, 43d0c8ec), 159, 67}, - {GRISU_UINT64_C(0x90e40fbe, ea1d3a4b), 176, 72}, - {GRISU_UINT64_C(0xdd15fe86, affad912), 192, 77}, - {GRISU_UINT64_C(0xa8acd7c0, 222311bd), 209, 82}, - {GRISU_UINT64_C(0x80b05e5a, c60b6178), 226, 87}, - {GRISU_UINT64_C(0xc45d1df9, 42711d9a), 242, 92}, - {GRISU_UINT64_C(0x95d04aee, 3b80ece6), 259, 97}, - {GRISU_UINT64_C(0xe498f455, c38b997a), 275, 102}, - {GRISU_UINT64_C(0xae67f1e9, aec07188), 292, 107}, - {GRISU_UINT64_C(0x850fadc0, 9923329e), 309, 112}, - {GRISU_UINT64_C(0xcb090c80, 01ab551c), 325, 117}, - {GRISU_UINT64_C(0x9ae75759, 6946075f), 342, 122}, - {GRISU_UINT64_C(0xec5d3fa8, ce427b00), 358, 127}, - {GRISU_UINT64_C(0xb454e4a1, 79dd1877), 375, 132}, - {GRISU_UINT64_C(0x899504ae, 72497eba), 392, 137}, - {GRISU_UINT64_C(0xd1ef0244, af2364ff), 408, 142}, - {GRISU_UINT64_C(0xa02aa96b, 06deb0fe), 425, 147}, - {GRISU_UINT64_C(0xf46518c2, ef5b8cd1), 441, 152}, - {GRISU_UINT64_C(0xba756174, 393d88e0), 458, 157}, - {GRISU_UINT64_C(0x8e41ade9, fbebc27d), 475, 162}, - {GRISU_UINT64_C(0xd910f7ff, 28069da4), 491, 167}, - {GRISU_UINT64_C(0xa59bc234, db398c25), 508, 172}, - {GRISU_UINT64_C(0xfcb2cb35, e702af78), 524, 177}, - {GRISU_UINT64_C(0xc0cb28a9, 8fcf3c80), 541, 182}, - {GRISU_UINT64_C(0x9316ff75, dd87cbd8), 558, 187}, - {GRISU_UINT64_C(0xe070f78d, 3927556b), 574, 192}, - {GRISU_UINT64_C(0xab3c2fdd, eeaad25b), 591, 197}, - {GRISU_UINT64_C(0x82a45b45, 0226b39d), 608, 202}, - {GRISU_UINT64_C(0xc75809c4, 2c684dd1), 624, 207}, - {GRISU_UINT64_C(0x98165af3, 7b2153df), 641, 212}, - {GRISU_UINT64_C(0xe8111c87, c5c1ba9a), 657, 217}, - {GRISU_UINT64_C(0xb10d8e14, 56105dad), 674, 222}, - {GRISU_UINT64_C(0x8714a775, e3e95c78), 691, 227}, - {GRISU_UINT64_C(0xce1de406, 42e3f4b9), 707, 232}, - {GRISU_UINT64_C(0x9d412e08, 06e88aa6), 724, 237}, - {GRISU_UINT64_C(0xeff394dc, ff8a948f), 740, 242}, - {GRISU_UINT64_C(0xb7118682, dbb66a77), 757, 247}, - {GRISU_UINT64_C(0x8bab8eef, b6409c1a), 774, 252}, - {GRISU_UINT64_C(0xd51ea6fa, 85785631), 790, 257}, - {GRISU_UINT64_C(0xa298f2c5, 01f45f43), 807, 262}, - {GRISU_UINT64_C(0xf81aa16f, dc1b81db), 823, 267}, - {GRISU_UINT64_C(0xbd49d14a, a79dbc82), 840, 272}, - {GRISU_UINT64_C(0x906a617d, 450187e2), 857, 277}, - {GRISU_UINT64_C(0xdc5c5301, c56b75f7), 873, 282}, - {GRISU_UINT64_C(0xa81f3014, 49ee8c70), 890, 287}, - {GRISU_UINT64_C(0x80444b5e, 7aa7cf85), 907, 292}, - {GRISU_UINT64_C(0xc3b83581, 09e84f07), 923, 297}, - {GRISU_UINT64_C(0x95527a52, 02df0ccb), 940, 302}, - {GRISU_UINT64_C(0xe3d8f9e5, 63a198e5), 956, 307}, - {GRISU_UINT64_C(0xadd57a27, d29339f6), 973, 312}, - {GRISU_UINT64_C(0x849feec2, 81d7f329), 990, 317}, - {GRISU_UINT64_C(0xca5e89b1, 8b602368), 1006, 322}, - {GRISU_UINT64_C(0x9a65406d, 44a5c903), 1023, 327}, - {GRISU_UINT64_C(0xeb96bf6e, badf77d9), 1039, 332}, - {GRISU_UINT64_C(0xb3bd72ed, 2af29e20), 1056, 337}, - {GRISU_UINT64_C(0x892179be, 91d43a44), 1073, 342}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(5) = 17; -// nb elements (5): 131 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(6)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0xdb71e914, 32b1a24b), -1067, -302}, - {GRISU_UINT64_C(0xd1476e2c, 07286faa), -1047, -296}, - {GRISU_UINT64_C(0xc795830d, 75038c1e), -1027, -290}, - {GRISU_UINT64_C(0xbe5691ef, 416bd60c), -1007, -284}, - {GRISU_UINT64_C(0xb5854744, 8ffffb2e), -987, -278}, - {GRISU_UINT64_C(0xad1c8eab, 5ee43b67), -967, -272}, - {GRISU_UINT64_C(0xa5178fff, 668ae0b6), -947, -266}, - {GRISU_UINT64_C(0x9d71ac8f, ada6c9b5), -927, -260}, - {GRISU_UINT64_C(0x96267c75, 35b763b5), -907, -254}, - {GRISU_UINT64_C(0x8f31cc09, 37ae58d3), -887, -248}, - {GRISU_UINT64_C(0x888f9979, 7a5e012d), -867, -242}, - {GRISU_UINT64_C(0x823c1279, 5db6ce57), -847, -236}, - {GRISU_UINT64_C(0xf867241c, 8cc6d4c1), -828, -230}, - {GRISU_UINT64_C(0xece53cec, 4a314ebe), -808, -224}, - {GRISU_UINT64_C(0xe1ebce4d, c7f16dfc), -788, -218}, - {GRISU_UINT64_C(0xd77485cb, 25823ac7), -768, -212}, - {GRISU_UINT64_C(0xcd795be8, 70516656), -748, -206}, - {GRISU_UINT64_C(0xc3f490aa, 77bd60fd), -728, -200}, - {GRISU_UINT64_C(0xbae0a846, d2195713), -708, -194}, - {GRISU_UINT64_C(0xb23867fb, 2a35b28e), -688, -188}, - {GRISU_UINT64_C(0xa9f6d30a, 038d1dbc), -668, -182}, - {GRISU_UINT64_C(0xa21727db, 38cb0030), -648, -176}, - {GRISU_UINT64_C(0x9a94dd3e, 8cf578ba), -628, -170}, - {GRISU_UINT64_C(0x936b9fce, bb25c996), -608, -164}, - {GRISU_UINT64_C(0x8c974f73, 83725573), -588, -158}, - {GRISU_UINT64_C(0x8613fd01, 45877586), -568, -152}, - {GRISU_UINT64_C(0xffbbcfe9, 94e5c620), -549, -146}, - {GRISU_UINT64_C(0xf3e2f893, dec3f126), -529, -140}, - {GRISU_UINT64_C(0xe896a0d7, e51e1566), -509, -134}, - {GRISU_UINT64_C(0xddd0467c, 64bce4a1), -489, -128}, - {GRISU_UINT64_C(0xd389b478, 79823479), -469, -122}, - {GRISU_UINT64_C(0xc9bcff60, 34c13053), -449, -116}, - {GRISU_UINT64_C(0xc06481fb, 9bcf8d3a), -429, -110}, - {GRISU_UINT64_C(0xb77ada06, 17e3bbcb), -409, -104}, - {GRISU_UINT64_C(0xaefae514, 77a06b04), -389, -98}, - {GRISU_UINT64_C(0xa6dfbd9f, b8e5b88f), -369, -92}, - {GRISU_UINT64_C(0x9f24b832, e6b0f436), -349, -86}, - {GRISU_UINT64_C(0x97c560ba, 6b0919a6), -329, -80}, - {GRISU_UINT64_C(0x90bd77f3, 483bb9ba), -309, -74}, - {GRISU_UINT64_C(0x8a08f0f8, bf0f156b), -289, -68}, - {GRISU_UINT64_C(0x83a3eeee, f9153e89), -269, -62}, - {GRISU_UINT64_C(0xfb158592, be068d2f), -250, -56}, - {GRISU_UINT64_C(0xef73d256, a5c0f77d), -230, -50}, - {GRISU_UINT64_C(0xe45c10c4, 2a2b3b06), -210, -44}, - {GRISU_UINT64_C(0xd9c7dced, 53c72256), -190, -38}, - {GRISU_UINT64_C(0xcfb11ead, 453994ba), -170, -32}, - {GRISU_UINT64_C(0xc6120625, 76589ddb), -150, -26}, - {GRISU_UINT64_C(0xbce50864, 92111aeb), -130, -20}, - {GRISU_UINT64_C(0xb424dc35, 095cd80f), -110, -14}, - {GRISU_UINT64_C(0xabcc7711, 8461cefd), -90, -8}, - {GRISU_UINT64_C(0xa3d70a3d, 70a3d70a), -70, -2}, - {GRISU_UINT64_C(0x9c400000, 00000000), -50, 4}, - {GRISU_UINT64_C(0x9502f900, 00000000), -30, 10}, - {GRISU_UINT64_C(0x8e1bc9bf, 04000000), -10, 16}, - {GRISU_UINT64_C(0x87867832, 6eac9000), 10, 22}, - {GRISU_UINT64_C(0x813f3978, f8940984), 30, 28}, - {GRISU_UINT64_C(0xf684df56, c3e01bc7), 49, 34}, - {GRISU_UINT64_C(0xeb194f8e, 1ae525fd), 69, 40}, - {GRISU_UINT64_C(0xe0352f62, a19e306f), 89, 46}, - {GRISU_UINT64_C(0xd5d238a4, abe98068), 109, 52}, - {GRISU_UINT64_C(0xcbea6f8c, eb02bb3a), 129, 58}, - {GRISU_UINT64_C(0xc2781f49, ffcfa6d5), 149, 64}, - {GRISU_UINT64_C(0xb975d6b6, ee39e437), 169, 70}, - {GRISU_UINT64_C(0xb0de6538, 8cc8ada8), 189, 76}, - {GRISU_UINT64_C(0xa8acd7c0, 222311bd), 209, 82}, - {GRISU_UINT64_C(0xa0dc75f1, 778e39d6), 229, 88}, - {GRISU_UINT64_C(0x9968bf6a, bbe85f20), 249, 94}, - {GRISU_UINT64_C(0x924d692c, a61be758), 269, 100}, - {GRISU_UINT64_C(0x8b865b21, 5899f46d), 289, 106}, - {GRISU_UINT64_C(0x850fadc0, 9923329e), 309, 112}, - {GRISU_UINT64_C(0xfdcb4fa0, 02162a63), 328, 118}, - {GRISU_UINT64_C(0xf209787b, b47d6b85), 348, 124}, - {GRISU_UINT64_C(0xe6d3102a, d96cec1e), 368, 130}, - {GRISU_UINT64_C(0xdc21a117, 1d42645d), 388, 136}, - {GRISU_UINT64_C(0xd1ef0244, af2364ff), 408, 142}, - {GRISU_UINT64_C(0xc83553c5, c8965d3d), 428, 148}, - {GRISU_UINT64_C(0xbeeefb58, 4aff8604), 448, 154}, - {GRISU_UINT64_C(0xb616a12b, 7fe617aa), 468, 160}, - {GRISU_UINT64_C(0xada72ccc, 20054aea), 488, 166}, - {GRISU_UINT64_C(0xa59bc234, db398c25), 508, 172}, - {GRISU_UINT64_C(0x9defbf01, b061adab), 528, 178}, - {GRISU_UINT64_C(0x969eb7c4, 7859e744), 548, 184}, - {GRISU_UINT64_C(0x8fa47579, 1a569d11), 568, 190}, - {GRISU_UINT64_C(0x88fcf317, f22241e2), 588, 196}, - {GRISU_UINT64_C(0x82a45b45, 0226b39d), 608, 202}, - {GRISU_UINT64_C(0xf92e0c35, 37826146), 627, 208}, - {GRISU_UINT64_C(0xeda2ee1c, 7064130c), 647, 214}, - {GRISU_UINT64_C(0xe2a0b5dc, 971f303a), 667, 220}, - {GRISU_UINT64_C(0xd8210bef, d30efa5a), 687, 226}, - {GRISU_UINT64_C(0xce1de406, 42e3f4b9), 707, 232}, - {GRISU_UINT64_C(0xc491798a, 08a2ad4f), 727, 238}, - {GRISU_UINT64_C(0xbb764c4c, a7a44410), 747, 244}, - {GRISU_UINT64_C(0xb2c71d5b, ca9023f8), 767, 250}, - {GRISU_UINT64_C(0xaa7eebfb, 9df9de8e), 787, 256}, - {GRISU_UINT64_C(0xa298f2c5, 01f45f43), 807, 262}, - {GRISU_UINT64_C(0x9b10a4e5, e9913129), 827, 268}, - {GRISU_UINT64_C(0x93e1ab82, 52f33b46), 847, 274}, - {GRISU_UINT64_C(0x8d07e334, 55637eb3), 867, 280}, - {GRISU_UINT64_C(0x867f59a9, d4bed6c0), 887, 286}, - {GRISU_UINT64_C(0x80444b5e, 7aa7cf85), 907, 292}, - {GRISU_UINT64_C(0xf4a642e1, 4c6262c9), 926, 298}, - {GRISU_UINT64_C(0xe950df20, 247c83fd), 946, 304}, - {GRISU_UINT64_C(0xde81e40a, 034bcf50), 966, 310}, - {GRISU_UINT64_C(0xd433179d, 9c8cb841), 986, 316}, - {GRISU_UINT64_C(0xca5e89b1, 8b602368), 1006, 322}, - {GRISU_UINT64_C(0xc0fe9088, 95cf3b44), 1026, 328}, - {GRISU_UINT64_C(0xb80dc58e, 81fe95a1), 1046, 334}, - {GRISU_UINT64_C(0xaf87023b, 9bf0ee6b), 1066, 340}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(6) = 20; -// nb elements (6): 109 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(7)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0x892731ac, 9faf056f), -1063, -301}, - {GRISU_UINT64_C(0xa37fce12, 6597973d), -1040, -294}, - {GRISU_UINT64_C(0xc2e801fb, 244576d5), -1017, -287}, - {GRISU_UINT64_C(0xe858ad24, 8f5c22ca), -994, -280}, - {GRISU_UINT64_C(0x8a7d3eef, 7f1cfc52), -970, -273}, - {GRISU_UINT64_C(0xa5178fff, 668ae0b6), -947, -266}, - {GRISU_UINT64_C(0xc4ce17b3, 99107c23), -924, -259}, - {GRISU_UINT64_C(0xea9c2277, 23ee8bcb), -901, -252}, - {GRISU_UINT64_C(0x8bd6a141, 006042be), -877, -245}, - {GRISU_UINT64_C(0xa6b34ad8, c9dfc070), -854, -238}, - {GRISU_UINT64_C(0xc6b8e9b0, 709f109a), -831, -231}, - {GRISU_UINT64_C(0xece53cec, 4a314ebe), -808, -224}, - {GRISU_UINT64_C(0x8d3360f0, 9cf6e4bd), -784, -217}, - {GRISU_UINT64_C(0xa8530886, b54dbdec), -761, -210}, - {GRISU_UINT64_C(0xc8a883c0, fdaf7df0), -738, -203}, - {GRISU_UINT64_C(0xef340a98, 172aace5), -715, -196}, - {GRISU_UINT64_C(0x8e938662, 882af53e), -691, -189}, - {GRISU_UINT64_C(0xa9f6d30a, 038d1dbc), -668, -182}, - {GRISU_UINT64_C(0xca9cf1d2, 06fdc03c), -645, -175}, - {GRISU_UINT64_C(0xf18899b1, bc3f8ca2), -622, -168}, - {GRISU_UINT64_C(0x8ff71a0f, e2c2e6dc), -598, -161}, - {GRISU_UINT64_C(0xab9eb47c, 81f5114f), -575, -154}, - {GRISU_UINT64_C(0xcc963fee, 10b7d1b3), -552, -147}, - {GRISU_UINT64_C(0xf3e2f893, dec3f126), -529, -140}, - {GRISU_UINT64_C(0x915e2486, ef32cd60), -505, -133}, - {GRISU_UINT64_C(0xad4ab711, 2eb3929e), -482, -126}, - {GRISU_UINT64_C(0xce947a3d, a6a9273e), -459, -119}, - {GRISU_UINT64_C(0xf64335bc, f065d37d), -436, -112}, - {GRISU_UINT64_C(0x92c8ae6b, 464fc96f), -412, -105}, - {GRISU_UINT64_C(0xaefae514, 77a06b04), -389, -98}, - {GRISU_UINT64_C(0xd097ad07, a71f26b2), -366, -91}, - {GRISU_UINT64_C(0xf8a95fcf, 88747d94), -343, -84}, - {GRISU_UINT64_C(0x9436c076, 0c86e30c), -319, -77}, - {GRISU_UINT64_C(0xb0af48ec, 79ace837), -296, -70}, - {GRISU_UINT64_C(0xd29fe4b1, 8e88640f), -273, -63}, - {GRISU_UINT64_C(0xfb158592, be068d2f), -250, -56}, - {GRISU_UINT64_C(0x95a86376, 27989aae), -226, -49}, - {GRISU_UINT64_C(0xb267ed19, 40f1c61c), -203, -42}, - {GRISU_UINT64_C(0xd4ad2dbf, c3d07788), -180, -35}, - {GRISU_UINT64_C(0xfd87b5f2, 8300ca0e), -157, -28}, - {GRISU_UINT64_C(0x971da050, 74da7bef), -133, -21}, - {GRISU_UINT64_C(0xb424dc35, 095cd80f), -110, -14}, - {GRISU_UINT64_C(0xd6bf94d5, e57a42bc), -87, -7}, - {GRISU_UINT64_C(0x80000000, 00000000), -63, 0}, - {GRISU_UINT64_C(0x98968000, 00000000), -40, 7}, - {GRISU_UINT64_C(0xb5e620f4, 80000000), -17, 14}, - {GRISU_UINT64_C(0xd8d726b7, 177a8000), 6, 21}, - {GRISU_UINT64_C(0x813f3978, f8940984), 30, 28}, - {GRISU_UINT64_C(0x9a130b96, 3a6c115c), 53, 35}, - {GRISU_UINT64_C(0xb7abc627, 050305ae), 76, 42}, - {GRISU_UINT64_C(0xdaf3f046, 51d47b4c), 99, 49}, - {GRISU_UINT64_C(0x82818f12, 81ed44a0), 123, 56}, - {GRISU_UINT64_C(0x9b934c3b, 330c8577), 146, 63}, - {GRISU_UINT64_C(0xb975d6b6, ee39e437), 169, 70}, - {GRISU_UINT64_C(0xdd15fe86, affad912), 192, 77}, - {GRISU_UINT64_C(0x83c7088e, 1aab65db), 216, 84}, - {GRISU_UINT64_C(0x9d174b2d, cec0e47b), 239, 91}, - {GRISU_UINT64_C(0xbb445da9, ca61281f), 262, 98}, - {GRISU_UINT64_C(0xdf3d5e9b, c0f653e1), 285, 105}, - {GRISU_UINT64_C(0x850fadc0, 9923329e), 309, 112}, - {GRISU_UINT64_C(0x9e9f11c4, 014dda7e), 332, 119}, - {GRISU_UINT64_C(0xbd176620, a501fc00), 355, 126}, - {GRISU_UINT64_C(0xe16a1dc9, d8545e95), 378, 133}, - {GRISU_UINT64_C(0x865b8692, 5b9bc5c2), 402, 140}, - {GRISU_UINT64_C(0xa02aa96b, 06deb0fe), 425, 147}, - {GRISU_UINT64_C(0xbeeefb58, 4aff8604), 448, 154}, - {GRISU_UINT64_C(0xe39c4976, 5fdf9d95), 471, 161}, - {GRISU_UINT64_C(0x87aa9aff, 79042287), 495, 168}, - {GRISU_UINT64_C(0xa1ba1ba7, 9e1632dc), 518, 175}, - {GRISU_UINT64_C(0xc0cb28a9, 8fcf3c80), 541, 182}, - {GRISU_UINT64_C(0xe5d3ef28, 2a242e82), 564, 189}, - {GRISU_UINT64_C(0x88fcf317, f22241e2), 588, 196}, - {GRISU_UINT64_C(0xa34d7216, 42b06084), 611, 203}, - {GRISU_UINT64_C(0xc2abf989, 935ddbfe), 634, 210}, - {GRISU_UINT64_C(0xe8111c87, c5c1ba9a), 657, 217}, - {GRISU_UINT64_C(0x8a5296ff, e33cc930), 681, 224}, - {GRISU_UINT64_C(0xa4e4b66b, 68b65d61), 704, 231}, - {GRISU_UINT64_C(0xc491798a, 08a2ad4f), 727, 238}, - {GRISU_UINT64_C(0xea53df5f, d18d5514), 750, 245}, - {GRISU_UINT64_C(0x8bab8eef, b6409c1a), 774, 252}, - {GRISU_UINT64_C(0xa67ff273, b8460357), 797, 259}, - {GRISU_UINT64_C(0xc67bb459, 7ce2ce49), 820, 266}, - {GRISU_UINT64_C(0xec9c459d, 51852ba3), 843, 273}, - {GRISU_UINT64_C(0x8d07e334, 55637eb3), 867, 280}, - {GRISU_UINT64_C(0xa81f3014, 49ee8c70), 890, 287}, - {GRISU_UINT64_C(0xc86ab5c3, 9fa63441), 913, 294}, - {GRISU_UINT64_C(0xeeea5d50, 04981478), 936, 301}, - {GRISU_UINT64_C(0x8e679c2f, 5e44ff8f), 960, 308}, - {GRISU_UINT64_C(0xa9c2794a, e3a3c69b), 983, 315}, - {GRISU_UINT64_C(0xca5e89b1, 8b602368), 1006, 322}, - {GRISU_UINT64_C(0xf13e34aa, bb430a15), 1029, 329}, - {GRISU_UINT64_C(0x8fcac257, 558ee4e6), 1053, 336}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(7) = 24; -// nb elements (7): 93 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(8)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0xab70fe17, c79ac6ca), -1060, -300}, - {GRISU_UINT64_C(0xff77b1fc, bebcdc4f), -1034, -292}, - {GRISU_UINT64_C(0xbe5691ef, 416bd60c), -1007, -284}, - {GRISU_UINT64_C(0x8dd01fad, 907ffc3c), -980, -276}, - {GRISU_UINT64_C(0xd3515c28, 31559a83), -954, -268}, - {GRISU_UINT64_C(0x9d71ac8f, ada6c9b5), -927, -260}, - {GRISU_UINT64_C(0xea9c2277, 23ee8bcb), -901, -252}, - {GRISU_UINT64_C(0xaecc4991, 4078536d), -874, -244}, - {GRISU_UINT64_C(0x823c1279, 5db6ce57), -847, -236}, - {GRISU_UINT64_C(0xc2109436, 4dfb5637), -821, -228}, - {GRISU_UINT64_C(0x9096ea6f, 3848984f), -794, -220}, - {GRISU_UINT64_C(0xd77485cb, 25823ac7), -768, -212}, - {GRISU_UINT64_C(0xa086cfcd, 97bf97f4), -741, -204}, - {GRISU_UINT64_C(0xef340a98, 172aace5), -715, -196}, - {GRISU_UINT64_C(0xb23867fb, 2a35b28e), -688, -188}, - {GRISU_UINT64_C(0x84c8d4df, d2c63f3b), -661, -180}, - {GRISU_UINT64_C(0xc5dd4427, 1ad3cdba), -635, -172}, - {GRISU_UINT64_C(0x936b9fce, bb25c996), -608, -164}, - {GRISU_UINT64_C(0xdbac6c24, 7d62a584), -582, -156}, - {GRISU_UINT64_C(0xa3ab6658, 0d5fdaf6), -555, -148}, - {GRISU_UINT64_C(0xf3e2f893, dec3f126), -529, -140}, - {GRISU_UINT64_C(0xb5b5ada8, aaff80b8), -502, -132}, - {GRISU_UINT64_C(0x87625f05, 6c7c4a8b), -475, -124}, - {GRISU_UINT64_C(0xc9bcff60, 34c13053), -449, -116}, - {GRISU_UINT64_C(0x964e858c, 91ba2655), -422, -108}, - {GRISU_UINT64_C(0xdff97724, 70297ebd), -396, -100}, - {GRISU_UINT64_C(0xa6dfbd9f, b8e5b88f), -369, -92}, - {GRISU_UINT64_C(0xf8a95fcf, 88747d94), -343, -84}, - {GRISU_UINT64_C(0xb9447093, 8fa89bcf), -316, -76}, - {GRISU_UINT64_C(0x8a08f0f8, bf0f156b), -289, -68}, - {GRISU_UINT64_C(0xcdb02555, 653131b6), -263, -60}, - {GRISU_UINT64_C(0x993fe2c6, d07b7fac), -236, -52}, - {GRISU_UINT64_C(0xe45c10c4, 2a2b3b06), -210, -44}, - {GRISU_UINT64_C(0xaa242499, 697392d3), -183, -36}, - {GRISU_UINT64_C(0xfd87b5f2, 8300ca0e), -157, -28}, - {GRISU_UINT64_C(0xbce50864, 92111aeb), -130, -20}, - {GRISU_UINT64_C(0x8cbccc09, 6f5088cc), -103, -12}, - {GRISU_UINT64_C(0xd1b71758, e219652c), -77, -4}, - {GRISU_UINT64_C(0x9c400000, 00000000), -50, 4}, - {GRISU_UINT64_C(0xe8d4a510, 00000000), -24, 12}, - {GRISU_UINT64_C(0xad78ebc5, ac620000), 3, 20}, - {GRISU_UINT64_C(0x813f3978, f8940984), 30, 28}, - {GRISU_UINT64_C(0xc097ce7b, c90715b3), 56, 36}, - {GRISU_UINT64_C(0x8f7e32ce, 7bea5c70), 83, 44}, - {GRISU_UINT64_C(0xd5d238a4, abe98068), 109, 52}, - {GRISU_UINT64_C(0x9f4f2726, 179a2245), 136, 60}, - {GRISU_UINT64_C(0xed63a231, d4c4fb27), 162, 68}, - {GRISU_UINT64_C(0xb0de6538, 8cc8ada8), 189, 76}, - {GRISU_UINT64_C(0x83c7088e, 1aab65db), 216, 84}, - {GRISU_UINT64_C(0xc45d1df9, 42711d9a), 242, 92}, - {GRISU_UINT64_C(0x924d692c, a61be758), 269, 100}, - {GRISU_UINT64_C(0xda01ee64, 1a708dea), 295, 108}, - {GRISU_UINT64_C(0xa26da399, 9aef774a), 322, 116}, - {GRISU_UINT64_C(0xf209787b, b47d6b85), 348, 124}, - {GRISU_UINT64_C(0xb454e4a1, 79dd1877), 375, 132}, - {GRISU_UINT64_C(0x865b8692, 5b9bc5c2), 402, 140}, - {GRISU_UINT64_C(0xc83553c5, c8965d3d), 428, 148}, - {GRISU_UINT64_C(0x952ab45c, fa97a0b3), 455, 156}, - {GRISU_UINT64_C(0xde469fbd, 99a05fe3), 481, 164}, - {GRISU_UINT64_C(0xa59bc234, db398c25), 508, 172}, - {GRISU_UINT64_C(0xf6c69a72, a3989f5c), 534, 180}, - {GRISU_UINT64_C(0xb7dcbf53, 54e9bece), 561, 188}, - {GRISU_UINT64_C(0x88fcf317, f22241e2), 588, 196}, - {GRISU_UINT64_C(0xcc20ce9b, d35c78a5), 614, 204}, - {GRISU_UINT64_C(0x98165af3, 7b2153df), 641, 212}, - {GRISU_UINT64_C(0xe2a0b5dc, 971f303a), 667, 220}, - {GRISU_UINT64_C(0xa8d9d153, 5ce3b396), 694, 228}, - {GRISU_UINT64_C(0xfb9b7cd9, a4a7443c), 720, 236}, - {GRISU_UINT64_C(0xbb764c4c, a7a44410), 747, 244}, - {GRISU_UINT64_C(0x8bab8eef, b6409c1a), 774, 252}, - {GRISU_UINT64_C(0xd01fef10, a657842c), 800, 260}, - {GRISU_UINT64_C(0x9b10a4e5, e9913129), 827, 268}, - {GRISU_UINT64_C(0xe7109bfb, a19c0c9d), 853, 276}, - {GRISU_UINT64_C(0xac2820d9, 623bf429), 880, 284}, - {GRISU_UINT64_C(0x80444b5e, 7aa7cf85), 907, 292}, - {GRISU_UINT64_C(0xbf21e440, 03acdd2d), 933, 300}, - {GRISU_UINT64_C(0x8e679c2f, 5e44ff8f), 960, 308}, - {GRISU_UINT64_C(0xd433179d, 9c8cb841), 986, 316}, - {GRISU_UINT64_C(0x9e19db92, b4e31ba9), 1013, 324}, - {GRISU_UINT64_C(0xeb96bf6e, badf77d9), 1039, 332}, - {GRISU_UINT64_C(0xaf87023b, 9bf0ee6b), 1066, 340}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(8) = 27; -// nb elements (8): 82 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(9)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0xd64d3d9d, b981787d), -1057, -299}, - {GRISU_UINT64_C(0xc795830d, 75038c1e), -1027, -290}, - {GRISU_UINT64_C(0xb9e08a83, a5e34f08), -997, -281}, - {GRISU_UINT64_C(0xad1c8eab, 5ee43b67), -967, -272}, - {GRISU_UINT64_C(0xa139029f, 6a239f72), -937, -263}, - {GRISU_UINT64_C(0x96267c75, 35b763b5), -907, -254}, - {GRISU_UINT64_C(0x8bd6a141, 006042be), -877, -245}, - {GRISU_UINT64_C(0x823c1279, 5db6ce57), -847, -236}, - {GRISU_UINT64_C(0xf294b943, e17a2bc4), -818, -227}, - {GRISU_UINT64_C(0xe1ebce4d, c7f16dfc), -788, -218}, - {GRISU_UINT64_C(0xd267caa8, 62a12d67), -758, -209}, - {GRISU_UINT64_C(0xc3f490aa, 77bd60fd), -728, -200}, - {GRISU_UINT64_C(0xb67f6455, 292cbf08), -698, -191}, - {GRISU_UINT64_C(0xa9f6d30a, 038d1dbc), -668, -182}, - {GRISU_UINT64_C(0x9e4a9cec, 15763e2f), -638, -173}, - {GRISU_UINT64_C(0x936b9fce, bb25c996), -608, -164}, - {GRISU_UINT64_C(0x894bc396, ce5da772), -578, -155}, - {GRISU_UINT64_C(0xffbbcfe9, 94e5c620), -549, -146}, - {GRISU_UINT64_C(0xee2ba6c0, 678b597f), -519, -137}, - {GRISU_UINT64_C(0xddd0467c, 64bce4a1), -489, -128}, - {GRISU_UINT64_C(0xce947a3d, a6a9273e), -459, -119}, - {GRISU_UINT64_C(0xc06481fb, 9bcf8d3a), -429, -110}, - {GRISU_UINT64_C(0xb32df8e9, f3546564), -399, -101}, - {GRISU_UINT64_C(0xa6dfbd9f, b8e5b88f), -369, -92}, - {GRISU_UINT64_C(0x9b69dbe1, b548ce7d), -339, -83}, - {GRISU_UINT64_C(0x90bd77f3, 483bb9ba), -309, -74}, - {GRISU_UINT64_C(0x86ccbb52, ea94baeb), -279, -65}, - {GRISU_UINT64_C(0xfb158592, be068d2f), -250, -56}, - {GRISU_UINT64_C(0xe9d71b68, 9dde71b0), -220, -47}, - {GRISU_UINT64_C(0xd9c7dced, 53c72256), -190, -38}, - {GRISU_UINT64_C(0xcad2f7f5, 359a3b3e), -160, -29}, - {GRISU_UINT64_C(0xbce50864, 92111aeb), -130, -20}, - {GRISU_UINT64_C(0xafebff0b, cb24aaff), -100, -11}, - {GRISU_UINT64_C(0xa3d70a3d, 70a3d70a), -70, -2}, - {GRISU_UINT64_C(0x98968000, 00000000), -40, 7}, - {GRISU_UINT64_C(0x8e1bc9bf, 04000000), -10, 16}, - {GRISU_UINT64_C(0x84595161, 401484a0), 20, 25}, - {GRISU_UINT64_C(0xf684df56, c3e01bc7), 49, 34}, - {GRISU_UINT64_C(0xe596b7b0, c643c719), 79, 43}, - {GRISU_UINT64_C(0xd5d238a4, abe98068), 109, 52}, - {GRISU_UINT64_C(0xc722f0ef, 9d80aad6), 139, 61}, - {GRISU_UINT64_C(0xb975d6b6, ee39e437), 169, 70}, - {GRISU_UINT64_C(0xacb92ed9, 397bf996), 199, 79}, - {GRISU_UINT64_C(0xa0dc75f1, 778e39d6), 229, 88}, - {GRISU_UINT64_C(0x95d04aee, 3b80ece6), 259, 97}, - {GRISU_UINT64_C(0x8b865b21, 5899f46d), 289, 106}, - {GRISU_UINT64_C(0x81f14fae, 158c5f6e), 319, 115}, - {GRISU_UINT64_C(0xf209787b, b47d6b85), 348, 124}, - {GRISU_UINT64_C(0xe16a1dc9, d8545e95), 378, 133}, - {GRISU_UINT64_C(0xd1ef0244, af2364ff), 408, 142}, - {GRISU_UINT64_C(0xc38413cf, 25e2d70e), 438, 151}, - {GRISU_UINT64_C(0xb616a12b, 7fe617aa), 468, 160}, - {GRISU_UINT64_C(0xa99541bf, 57452b28), 498, 169}, - {GRISU_UINT64_C(0x9defbf01, b061adab), 528, 178}, - {GRISU_UINT64_C(0x9316ff75, dd87cbd8), 558, 187}, - {GRISU_UINT64_C(0x88fcf317, f22241e2), 588, 196}, - {GRISU_UINT64_C(0xff290242, c83396ce), 617, 205}, - {GRISU_UINT64_C(0xeda2ee1c, 7064130c), 647, 214}, - {GRISU_UINT64_C(0xdd50f199, 6b947519), 677, 223}, - {GRISU_UINT64_C(0xce1de406, 42e3f4b9), 707, 232}, - {GRISU_UINT64_C(0xbff610b0, cc6edd3f), 737, 241}, - {GRISU_UINT64_C(0xb2c71d5b, ca9023f8), 767, 250}, - {GRISU_UINT64_C(0xa67ff273, b8460357), 797, 259}, - {GRISU_UINT64_C(0x9b10a4e5, e9913129), 827, 268}, - {GRISU_UINT64_C(0x906a617d, 450187e2), 857, 277}, - {GRISU_UINT64_C(0x867f59a9, d4bed6c0), 887, 286}, - {GRISU_UINT64_C(0xfa856334, 878fc151), 916, 295}, - {GRISU_UINT64_C(0xe950df20, 247c83fd), 946, 304}, - {GRISU_UINT64_C(0xd94ad8b1, c7380874), 976, 313}, - {GRISU_UINT64_C(0xca5e89b1, 8b602368), 1006, 322}, - {GRISU_UINT64_C(0xbc789925, 624c5fe1), 1036, 331}, - {GRISU_UINT64_C(0xaf87023b, 9bf0ee6b), 1066, 340}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(9) = 30; -// nb elements (9): 73 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(10)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0x85f04682, 93f0eb4e), -1053, -298}, - {GRISU_UINT64_C(0x9becce62, 836ac577), -1020, -288}, - {GRISU_UINT64_C(0xb5854744, 8ffffb2e), -987, -278}, - {GRISU_UINT64_C(0xd3515c28, 31559a83), -954, -268}, - {GRISU_UINT64_C(0xf6019da0, 7f549b2b), -921, -258}, - {GRISU_UINT64_C(0x8f31cc09, 37ae58d3), -887, -248}, - {GRISU_UINT64_C(0xa6b34ad8, c9dfc070), -854, -238}, - {GRISU_UINT64_C(0xc2109436, 4dfb5637), -821, -228}, - {GRISU_UINT64_C(0xe1ebce4d, c7f16dfc), -788, -218}, - {GRISU_UINT64_C(0x8380dea9, 3da4bc60), -754, -208}, - {GRISU_UINT64_C(0x99171105, 2d8bf3c5), -721, -198}, - {GRISU_UINT64_C(0xb23867fb, 2a35b28e), -688, -188}, - {GRISU_UINT64_C(0xcf79cc9d, b955c2cc), -655, -178}, - {GRISU_UINT64_C(0xf18899b1, bc3f8ca2), -622, -168}, - {GRISU_UINT64_C(0x8c974f73, 83725573), -588, -158}, - {GRISU_UINT64_C(0xa3ab6658, 0d5fdaf6), -555, -148}, - {GRISU_UINT64_C(0xbe895233, 86091466), -522, -138}, - {GRISU_UINT64_C(0xddd0467c, 64bce4a1), -489, -128}, - {GRISU_UINT64_C(0x811ccc66, 8829b887), -455, -118}, - {GRISU_UINT64_C(0x964e858c, 91ba2655), -422, -108}, - {GRISU_UINT64_C(0xaefae514, 77a06b04), -389, -98}, - {GRISU_UINT64_C(0xcbb41ef9, 79346bca), -356, -88}, - {GRISU_UINT64_C(0xed246723, 473e3813), -323, -78}, - {GRISU_UINT64_C(0x8a08f0f8, bf0f156b), -289, -68}, - {GRISU_UINT64_C(0xa0b19d2a, b70e6ed6), -256, -58}, - {GRISU_UINT64_C(0xbb127c53, b17ec159), -223, -48}, - {GRISU_UINT64_C(0xd9c7dced, 53c72256), -190, -38}, - {GRISU_UINT64_C(0xfd87b5f2, 8300ca0e), -157, -28}, - {GRISU_UINT64_C(0x9392ee8e, 921d5d07), -123, -18}, - {GRISU_UINT64_C(0xabcc7711, 8461cefd), -90, -8}, - {GRISU_UINT64_C(0xc8000000, 00000000), -57, 2}, - {GRISU_UINT64_C(0xe8d4a510, 00000000), -24, 12}, - {GRISU_UINT64_C(0x87867832, 6eac9000), 10, 22}, - {GRISU_UINT64_C(0x9dc5ada8, 2b70b59e), 43, 32}, - {GRISU_UINT64_C(0xb7abc627, 050305ae), 76, 42}, - {GRISU_UINT64_C(0xd5d238a4, abe98068), 109, 52}, - {GRISU_UINT64_C(0xf8ebad2b, 84e0d58c), 142, 62}, - {GRISU_UINT64_C(0x90e40fbe, ea1d3a4b), 176, 72}, - {GRISU_UINT64_C(0xa8acd7c0, 222311bd), 209, 82}, - {GRISU_UINT64_C(0xc45d1df9, 42711d9a), 242, 92}, - {GRISU_UINT64_C(0xe498f455, c38b997a), 275, 102}, - {GRISU_UINT64_C(0x850fadc0, 9923329e), 309, 112}, - {GRISU_UINT64_C(0x9ae75759, 6946075f), 342, 122}, - {GRISU_UINT64_C(0xb454e4a1, 79dd1877), 375, 132}, - {GRISU_UINT64_C(0xd1ef0244, af2364ff), 408, 142}, - {GRISU_UINT64_C(0xf46518c2, ef5b8cd1), 441, 152}, - {GRISU_UINT64_C(0x8e41ade9, fbebc27d), 475, 162}, - {GRISU_UINT64_C(0xa59bc234, db398c25), 508, 172}, - {GRISU_UINT64_C(0xc0cb28a9, 8fcf3c80), 541, 182}, - {GRISU_UINT64_C(0xe070f78d, 3927556b), 574, 192}, - {GRISU_UINT64_C(0x82a45b45, 0226b39d), 608, 202}, - {GRISU_UINT64_C(0x98165af3, 7b2153df), 641, 212}, - {GRISU_UINT64_C(0xb10d8e14, 56105dad), 674, 222}, - {GRISU_UINT64_C(0xce1de406, 42e3f4b9), 707, 232}, - {GRISU_UINT64_C(0xeff394dc, ff8a948f), 740, 242}, - {GRISU_UINT64_C(0x8bab8eef, b6409c1a), 774, 252}, - {GRISU_UINT64_C(0xa298f2c5, 01f45f43), 807, 262}, - {GRISU_UINT64_C(0xbd49d14a, a79dbc82), 840, 272}, - {GRISU_UINT64_C(0xdc5c5301, c56b75f7), 873, 282}, - {GRISU_UINT64_C(0x80444b5e, 7aa7cf85), 907, 292}, - {GRISU_UINT64_C(0x95527a52, 02df0ccb), 940, 302}, - {GRISU_UINT64_C(0xadd57a27, d29339f6), 973, 312}, - {GRISU_UINT64_C(0xca5e89b1, 8b602368), 1006, 322}, - {GRISU_UINT64_C(0xeb96bf6e, badf77d9), 1039, 332}, - {GRISU_UINT64_C(0x892179be, 91d43a44), 1073, 342}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(10) = 34; -// nb elements (10): 66 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(11)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0xa76c5823, 38ed2622), -1050, -297}, - {GRISU_UINT64_C(0xf3a20279, ed56d48a), -1014, -286}, - {GRISU_UINT64_C(0xb1442798, f49ffb4b), -977, -275}, - {GRISU_UINT64_C(0x80fa687f, 881c7f8e), -940, -264}, - {GRISU_UINT64_C(0xbbb01b92, 83253ca3), -904, -253}, - {GRISU_UINT64_C(0x888f9979, 7a5e012d), -867, -242}, - {GRISU_UINT64_C(0xc6b8e9b0, 709f109a), -831, -231}, - {GRISU_UINT64_C(0x9096ea6f, 3848984f), -794, -220}, - {GRISU_UINT64_C(0xd267caa8, 62a12d67), -758, -209}, - {GRISU_UINT64_C(0x99171105, 2d8bf3c5), -721, -198}, - {GRISU_UINT64_C(0xdec681f9, f4c31f31), -685, -187}, - {GRISU_UINT64_C(0xa21727db, 38cb0030), -648, -176}, - {GRISU_UINT64_C(0xebdf6617, 91d60f56), -612, -165}, - {GRISU_UINT64_C(0xab9eb47c, 81f5114f), -575, -154}, - {GRISU_UINT64_C(0xf9bd690a, 1b68637b), -539, -143}, - {GRISU_UINT64_C(0xb5b5ada8, aaff80b8), -502, -132}, - {GRISU_UINT64_C(0x843610cb, 4bf160cc), -465, -121}, - {GRISU_UINT64_C(0xc06481fb, 9bcf8d3a), -429, -110}, - {GRISU_UINT64_C(0x8bfbea76, c619ef36), -392, -99}, - {GRISU_UINT64_C(0xcbb41ef9, 79346bca), -356, -88}, - {GRISU_UINT64_C(0x9436c076, 0c86e30c), -319, -77}, - {GRISU_UINT64_C(0xd7adf884, aa879177), -283, -66}, - {GRISU_UINT64_C(0x9ced737b, b6c4183d), -246, -55}, - {GRISU_UINT64_C(0xe45c10c4, 2a2b3b06), -210, -44}, - {GRISU_UINT64_C(0xa6274bbd, d0fadd62), -173, -33}, - {GRISU_UINT64_C(0xf1c90080, baf72cb1), -137, -22}, - {GRISU_UINT64_C(0xafebff0b, cb24aaff), -100, -11}, - {GRISU_UINT64_C(0x80000000, 00000000), -63, 0}, - {GRISU_UINT64_C(0xba43b740, 00000000), -27, 11}, - {GRISU_UINT64_C(0x87867832, 6eac9000), 10, 22}, - {GRISU_UINT64_C(0xc5371912, 364ce305), 46, 33}, - {GRISU_UINT64_C(0x8f7e32ce, 7bea5c70), 83, 44}, - {GRISU_UINT64_C(0xd0cf4b50, cfe20766), 119, 55}, - {GRISU_UINT64_C(0x97edd871, cfda3a57), 156, 66}, - {GRISU_UINT64_C(0xdd15fe86, affad912), 192, 77}, - {GRISU_UINT64_C(0xa0dc75f1, 778e39d6), 229, 88}, - {GRISU_UINT64_C(0xea157514, 3cf97227), 265, 99}, - {GRISU_UINT64_C(0xaa51823e, 34a7eedf), 302, 110}, - {GRISU_UINT64_C(0xf7d88bc2, 4209a565), 338, 121}, - {GRISU_UINT64_C(0xb454e4a1, 79dd1877), 375, 132}, - {GRISU_UINT64_C(0x8335616a, ed761f1f), 412, 143}, - {GRISU_UINT64_C(0xbeeefb58, 4aff8604), 448, 154}, - {GRISU_UINT64_C(0x8aec23d6, 80043bee), 485, 165}, - {GRISU_UINT64_C(0xca28a291, 859bbf93), 521, 176}, - {GRISU_UINT64_C(0x9316ff75, dd87cbd8), 558, 187}, - {GRISU_UINT64_C(0xd60b3bd5, 6a5586f2), 594, 198}, - {GRISU_UINT64_C(0x9bbcc7a1, 42b17ccc), 631, 209}, - {GRISU_UINT64_C(0xe2a0b5dc, 971f303a), 667, 220}, - {GRISU_UINT64_C(0xa4e4b66b, 68b65d61), 704, 231}, - {GRISU_UINT64_C(0xeff394dc, ff8a948f), 740, 242}, - {GRISU_UINT64_C(0xae9672ab, a3d0c321), 777, 253}, - {GRISU_UINT64_C(0xfe0efb53, d30dd4d8), 813, 264}, - {GRISU_UINT64_C(0xb8da1662, e7b00a17), 850, 275}, - {GRISU_UINT64_C(0x867f59a9, d4bed6c0), 887, 286}, - {GRISU_UINT64_C(0xc3b83581, 09e84f07), 923, 297}, - {GRISU_UINT64_C(0x8e679c2f, 5e44ff8f), 960, 308}, - {GRISU_UINT64_C(0xcf39e50f, eae16bf0), 996, 319}, - {GRISU_UINT64_C(0x96c6e0ea, b509e64d), 1033, 330}, - {GRISU_UINT64_C(0xdb68c2ca, 82ed2a06), 1069, 341}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(11) = 37; -// nb elements (11): 60 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(12)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0xd1476e2c, 07286faa), -1047, -296}, - {GRISU_UINT64_C(0xbe5691ef, 416bd60c), -1007, -284}, - {GRISU_UINT64_C(0xad1c8eab, 5ee43b67), -967, -272}, - {GRISU_UINT64_C(0x9d71ac8f, ada6c9b5), -927, -260}, - {GRISU_UINT64_C(0x8f31cc09, 37ae58d3), -887, -248}, - {GRISU_UINT64_C(0x823c1279, 5db6ce57), -847, -236}, - {GRISU_UINT64_C(0xece53cec, 4a314ebe), -808, -224}, - {GRISU_UINT64_C(0xd77485cb, 25823ac7), -768, -212}, - {GRISU_UINT64_C(0xc3f490aa, 77bd60fd), -728, -200}, - {GRISU_UINT64_C(0xb23867fb, 2a35b28e), -688, -188}, - {GRISU_UINT64_C(0xa21727db, 38cb0030), -648, -176}, - {GRISU_UINT64_C(0x936b9fce, bb25c996), -608, -164}, - {GRISU_UINT64_C(0x8613fd01, 45877586), -568, -152}, - {GRISU_UINT64_C(0xf3e2f893, dec3f126), -529, -140}, - {GRISU_UINT64_C(0xddd0467c, 64bce4a1), -489, -128}, - {GRISU_UINT64_C(0xc9bcff60, 34c13053), -449, -116}, - {GRISU_UINT64_C(0xb77ada06, 17e3bbcb), -409, -104}, - {GRISU_UINT64_C(0xa6dfbd9f, b8e5b88f), -369, -92}, - {GRISU_UINT64_C(0x97c560ba, 6b0919a6), -329, -80}, - {GRISU_UINT64_C(0x8a08f0f8, bf0f156b), -289, -68}, - {GRISU_UINT64_C(0xfb158592, be068d2f), -250, -56}, - {GRISU_UINT64_C(0xe45c10c4, 2a2b3b06), -210, -44}, - {GRISU_UINT64_C(0xcfb11ead, 453994ba), -170, -32}, - {GRISU_UINT64_C(0xbce50864, 92111aeb), -130, -20}, - {GRISU_UINT64_C(0xabcc7711, 8461cefd), -90, -8}, - {GRISU_UINT64_C(0x9c400000, 00000000), -50, 4}, - {GRISU_UINT64_C(0x8e1bc9bf, 04000000), -10, 16}, - {GRISU_UINT64_C(0x813f3978, f8940984), 30, 28}, - {GRISU_UINT64_C(0xeb194f8e, 1ae525fd), 69, 40}, - {GRISU_UINT64_C(0xd5d238a4, abe98068), 109, 52}, - {GRISU_UINT64_C(0xc2781f49, ffcfa6d5), 149, 64}, - {GRISU_UINT64_C(0xb0de6538, 8cc8ada8), 189, 76}, - {GRISU_UINT64_C(0xa0dc75f1, 778e39d6), 229, 88}, - {GRISU_UINT64_C(0x924d692c, a61be758), 269, 100}, - {GRISU_UINT64_C(0x850fadc0, 9923329e), 309, 112}, - {GRISU_UINT64_C(0xf209787b, b47d6b85), 348, 124}, - {GRISU_UINT64_C(0xdc21a117, 1d42645d), 388, 136}, - {GRISU_UINT64_C(0xc83553c5, c8965d3d), 428, 148}, - {GRISU_UINT64_C(0xb616a12b, 7fe617aa), 468, 160}, - {GRISU_UINT64_C(0xa59bc234, db398c25), 508, 172}, - {GRISU_UINT64_C(0x969eb7c4, 7859e744), 548, 184}, - {GRISU_UINT64_C(0x88fcf317, f22241e2), 588, 196}, - {GRISU_UINT64_C(0xf92e0c35, 37826146), 627, 208}, - {GRISU_UINT64_C(0xe2a0b5dc, 971f303a), 667, 220}, - {GRISU_UINT64_C(0xce1de406, 42e3f4b9), 707, 232}, - {GRISU_UINT64_C(0xbb764c4c, a7a44410), 747, 244}, - {GRISU_UINT64_C(0xaa7eebfb, 9df9de8e), 787, 256}, - {GRISU_UINT64_C(0x9b10a4e5, e9913129), 827, 268}, - {GRISU_UINT64_C(0x8d07e334, 55637eb3), 867, 280}, - {GRISU_UINT64_C(0x80444b5e, 7aa7cf85), 907, 292}, - {GRISU_UINT64_C(0xe950df20, 247c83fd), 946, 304}, - {GRISU_UINT64_C(0xd433179d, 9c8cb841), 986, 316}, - {GRISU_UINT64_C(0xc0fe9088, 95cf3b44), 1026, 328}, - {GRISU_UINT64_C(0xaf87023b, 9bf0ee6b), 1066, 340}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(12) = 40; -// nb elements (12): 55 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(13)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0x82cca4db, 847945ca), -1043, -295}, - {GRISU_UINT64_C(0x94b3a202, eb1c3f39), -1000, -282}, - {GRISU_UINT64_C(0xa90de353, 5aaae202), -957, -269}, - {GRISU_UINT64_C(0xc0314325, 637a193a), -914, -256}, - {GRISU_UINT64_C(0xda7f5bf5, 90966849), -871, -243}, - {GRISU_UINT64_C(0xf867241c, 8cc6d4c1), -828, -230}, - {GRISU_UINT64_C(0x8d3360f0, 9cf6e4bd), -784, -217}, - {GRISU_UINT64_C(0xa086cfcd, 97bf97f4), -741, -204}, - {GRISU_UINT64_C(0xb67f6455, 292cbf08), -698, -191}, - {GRISU_UINT64_C(0xcf79cc9d, b955c2cc), -655, -178}, - {GRISU_UINT64_C(0xebdf6617, 91d60f56), -612, -165}, - {GRISU_UINT64_C(0x8613fd01, 45877586), -568, -152}, - {GRISU_UINT64_C(0x986ddb5c, 6b3a76b8), -525, -139}, - {GRISU_UINT64_C(0xad4ab711, 2eb3929e), -482, -126}, - {GRISU_UINT64_C(0xc5029163, f384a931), -439, -113}, - {GRISU_UINT64_C(0xdff97724, 70297ebd), -396, -100}, - {GRISU_UINT64_C(0xfea126b7, d78186bd), -353, -87}, - {GRISU_UINT64_C(0x90bd77f3, 483bb9ba), -309, -74}, - {GRISU_UINT64_C(0xa48ceaaa, b75a8e2b), -266, -61}, - {GRISU_UINT64_C(0xbb127c53, b17ec159), -223, -48}, - {GRISU_UINT64_C(0xd4ad2dbf, c3d07788), -180, -35}, - {GRISU_UINT64_C(0xf1c90080, baf72cb1), -137, -22}, - {GRISU_UINT64_C(0x89705f41, 36b4a597), -93, -9}, - {GRISU_UINT64_C(0x9c400000, 00000000), -50, 4}, - {GRISU_UINT64_C(0xb1a2bc2e, c5000000), -7, 17}, - {GRISU_UINT64_C(0xc9f2c9cd, 04674edf), 36, 30}, - {GRISU_UINT64_C(0xe596b7b0, c643c719), 79, 43}, - {GRISU_UINT64_C(0x82818f12, 81ed44a0), 123, 56}, - {GRISU_UINT64_C(0x945e455f, 24fb1cf9), 166, 69}, - {GRISU_UINT64_C(0xa8acd7c0, 222311bd), 209, 82}, - {GRISU_UINT64_C(0xbfc2ef45, 6ae276e9), 252, 95}, - {GRISU_UINT64_C(0xda01ee64, 1a708dea), 295, 108}, - {GRISU_UINT64_C(0xf7d88bc2, 4209a565), 338, 121}, - {GRISU_UINT64_C(0x8ce2529e, 2734bb1d), 382, 134}, - {GRISU_UINT64_C(0xa02aa96b, 06deb0fe), 425, 147}, - {GRISU_UINT64_C(0xb616a12b, 7fe617aa), 468, 160}, - {GRISU_UINT64_C(0xcf02b2c2, 1207ef2f), 511, 173}, - {GRISU_UINT64_C(0xeb57ff22, fc0c795a), 554, 186}, - {GRISU_UINT64_C(0x85c70565, 62757457), 598, 199}, - {GRISU_UINT64_C(0x98165af3, 7b2153df), 641, 212}, - {GRISU_UINT64_C(0xace73cbf, dc0bfb7b), 684, 225}, - {GRISU_UINT64_C(0xc491798a, 08a2ad4f), 727, 238}, - {GRISU_UINT64_C(0xdf78e4b2, bd342cf7), 770, 251}, - {GRISU_UINT64_C(0xfe0efb53, d30dd4d8), 813, 264}, - {GRISU_UINT64_C(0x906a617d, 450187e2), 857, 277}, - {GRISU_UINT64_C(0xa42e74f3, d032f526), 900, 290}, - {GRISU_UINT64_C(0xbaa718e6, 8396cffe), 943, 303}, - {GRISU_UINT64_C(0xd433179d, 9c8cb841), 986, 316}, - {GRISU_UINT64_C(0xf13e34aa, bb430a15), 1029, 329}, - {GRISU_UINT64_C(0x892179be, 91d43a44), 1073, 342}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(13) = 44; -// nb elements (13): 51 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(14)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0xa37fce12, 6597973d), -1040, -294}, - {GRISU_UINT64_C(0xe858ad24, 8f5c22ca), -994, -280}, - {GRISU_UINT64_C(0xa5178fff, 668ae0b6), -947, -266}, - {GRISU_UINT64_C(0xea9c2277, 23ee8bcb), -901, -252}, - {GRISU_UINT64_C(0xa6b34ad8, c9dfc070), -854, -238}, - {GRISU_UINT64_C(0xece53cec, 4a314ebe), -808, -224}, - {GRISU_UINT64_C(0xa8530886, b54dbdec), -761, -210}, - {GRISU_UINT64_C(0xef340a98, 172aace5), -715, -196}, - {GRISU_UINT64_C(0xa9f6d30a, 038d1dbc), -668, -182}, - {GRISU_UINT64_C(0xf18899b1, bc3f8ca2), -622, -168}, - {GRISU_UINT64_C(0xab9eb47c, 81f5114f), -575, -154}, - {GRISU_UINT64_C(0xf3e2f893, dec3f126), -529, -140}, - {GRISU_UINT64_C(0xad4ab711, 2eb3929e), -482, -126}, - {GRISU_UINT64_C(0xf64335bc, f065d37d), -436, -112}, - {GRISU_UINT64_C(0xaefae514, 77a06b04), -389, -98}, - {GRISU_UINT64_C(0xf8a95fcf, 88747d94), -343, -84}, - {GRISU_UINT64_C(0xb0af48ec, 79ace837), -296, -70}, - {GRISU_UINT64_C(0xfb158592, be068d2f), -250, -56}, - {GRISU_UINT64_C(0xb267ed19, 40f1c61c), -203, -42}, - {GRISU_UINT64_C(0xfd87b5f2, 8300ca0e), -157, -28}, - {GRISU_UINT64_C(0xb424dc35, 095cd80f), -110, -14}, - {GRISU_UINT64_C(0x80000000, 00000000), -63, 0}, - {GRISU_UINT64_C(0xb5e620f4, 80000000), -17, 14}, - {GRISU_UINT64_C(0x813f3978, f8940984), 30, 28}, - {GRISU_UINT64_C(0xb7abc627, 050305ae), 76, 42}, - {GRISU_UINT64_C(0x82818f12, 81ed44a0), 123, 56}, - {GRISU_UINT64_C(0xb975d6b6, ee39e437), 169, 70}, - {GRISU_UINT64_C(0x83c7088e, 1aab65db), 216, 84}, - {GRISU_UINT64_C(0xbb445da9, ca61281f), 262, 98}, - {GRISU_UINT64_C(0x850fadc0, 9923329e), 309, 112}, - {GRISU_UINT64_C(0xbd176620, a501fc00), 355, 126}, - {GRISU_UINT64_C(0x865b8692, 5b9bc5c2), 402, 140}, - {GRISU_UINT64_C(0xbeeefb58, 4aff8604), 448, 154}, - {GRISU_UINT64_C(0x87aa9aff, 79042287), 495, 168}, - {GRISU_UINT64_C(0xc0cb28a9, 8fcf3c80), 541, 182}, - {GRISU_UINT64_C(0x88fcf317, f22241e2), 588, 196}, - {GRISU_UINT64_C(0xc2abf989, 935ddbfe), 634, 210}, - {GRISU_UINT64_C(0x8a5296ff, e33cc930), 681, 224}, - {GRISU_UINT64_C(0xc491798a, 08a2ad4f), 727, 238}, - {GRISU_UINT64_C(0x8bab8eef, b6409c1a), 774, 252}, - {GRISU_UINT64_C(0xc67bb459, 7ce2ce49), 820, 266}, - {GRISU_UINT64_C(0x8d07e334, 55637eb3), 867, 280}, - {GRISU_UINT64_C(0xc86ab5c3, 9fa63441), 913, 294}, - {GRISU_UINT64_C(0x8e679c2f, 5e44ff8f), 960, 308}, - {GRISU_UINT64_C(0xca5e89b1, 8b602368), 1006, 322}, - {GRISU_UINT64_C(0x8fcac257, 558ee4e6), 1053, 336}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(14) = 47; -// nb elements (14): 47 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(15)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0xcc5fc196, fefd7d0c), -1037, -293}, - {GRISU_UINT64_C(0xb5854744, 8ffffb2e), -987, -278}, - {GRISU_UINT64_C(0xa139029f, 6a239f72), -937, -263}, - {GRISU_UINT64_C(0x8f31cc09, 37ae58d3), -887, -248}, - {GRISU_UINT64_C(0xfe5d5415, 0b090b03), -838, -233}, - {GRISU_UINT64_C(0xe1ebce4d, c7f16dfc), -788, -218}, - {GRISU_UINT64_C(0xc8a883c0, fdaf7df0), -738, -203}, - {GRISU_UINT64_C(0xb23867fb, 2a35b28e), -688, -188}, - {GRISU_UINT64_C(0x9e4a9cec, 15763e2f), -638, -173}, - {GRISU_UINT64_C(0x8c974f73, 83725573), -588, -158}, - {GRISU_UINT64_C(0xf9bd690a, 1b68637b), -539, -143}, - {GRISU_UINT64_C(0xddd0467c, 64bce4a1), -489, -128}, - {GRISU_UINT64_C(0xc5029163, f384a931), -439, -113}, - {GRISU_UINT64_C(0xaefae514, 77a06b04), -389, -98}, - {GRISU_UINT64_C(0x9b69dbe1, b548ce7d), -339, -83}, - {GRISU_UINT64_C(0x8a08f0f8, bf0f156b), -289, -68}, - {GRISU_UINT64_C(0xf5330471, 4d9265e0), -240, -53}, - {GRISU_UINT64_C(0xd9c7dced, 53c72256), -190, -38}, - {GRISU_UINT64_C(0xc16d9a00, 95928a27), -140, -23}, - {GRISU_UINT64_C(0xabcc7711, 8461cefd), -90, -8}, - {GRISU_UINT64_C(0x98968000, 00000000), -40, 7}, - {GRISU_UINT64_C(0x87867832, 6eac9000), 10, 22}, - {GRISU_UINT64_C(0xf0bdc21a, bb48db20), 59, 37}, - {GRISU_UINT64_C(0xd5d238a4, abe98068), 109, 52}, - {GRISU_UINT64_C(0xbde94e8e, 43d0c8ec), 159, 67}, - {GRISU_UINT64_C(0xa8acd7c0, 222311bd), 209, 82}, - {GRISU_UINT64_C(0x95d04aee, 3b80ece6), 259, 97}, - {GRISU_UINT64_C(0x850fadc0, 9923329e), 309, 112}, - {GRISU_UINT64_C(0xec5d3fa8, ce427b00), 358, 127}, - {GRISU_UINT64_C(0xd1ef0244, af2364ff), 408, 142}, - {GRISU_UINT64_C(0xba756174, 393d88e0), 458, 157}, - {GRISU_UINT64_C(0xa59bc234, db398c25), 508, 172}, - {GRISU_UINT64_C(0x9316ff75, dd87cbd8), 558, 187}, - {GRISU_UINT64_C(0x82a45b45, 0226b39d), 608, 202}, - {GRISU_UINT64_C(0xe8111c87, c5c1ba9a), 657, 217}, - {GRISU_UINT64_C(0xce1de406, 42e3f4b9), 707, 232}, - {GRISU_UINT64_C(0xb7118682, dbb66a77), 757, 247}, - {GRISU_UINT64_C(0xa298f2c5, 01f45f43), 807, 262}, - {GRISU_UINT64_C(0x906a617d, 450187e2), 857, 277}, - {GRISU_UINT64_C(0x80444b5e, 7aa7cf85), 907, 292}, - {GRISU_UINT64_C(0xe3d8f9e5, 63a198e5), 956, 307}, - {GRISU_UINT64_C(0xca5e89b1, 8b602368), 1006, 322}, - {GRISU_UINT64_C(0xb3bd72ed, 2af29e20), 1056, 337}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(15) = 50; -// nb elements (15): 44 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(16)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0xff77b1fc, bebcdc4f), -1034, -292}, - {GRISU_UINT64_C(0x8dd01fad, 907ffc3c), -980, -276}, - {GRISU_UINT64_C(0x9d71ac8f, ada6c9b5), -927, -260}, - {GRISU_UINT64_C(0xaecc4991, 4078536d), -874, -244}, - {GRISU_UINT64_C(0xc2109436, 4dfb5637), -821, -228}, - {GRISU_UINT64_C(0xd77485cb, 25823ac7), -768, -212}, - {GRISU_UINT64_C(0xef340a98, 172aace5), -715, -196}, - {GRISU_UINT64_C(0x84c8d4df, d2c63f3b), -661, -180}, - {GRISU_UINT64_C(0x936b9fce, bb25c996), -608, -164}, - {GRISU_UINT64_C(0xa3ab6658, 0d5fdaf6), -555, -148}, - {GRISU_UINT64_C(0xb5b5ada8, aaff80b8), -502, -132}, - {GRISU_UINT64_C(0xc9bcff60, 34c13053), -449, -116}, - {GRISU_UINT64_C(0xdff97724, 70297ebd), -396, -100}, - {GRISU_UINT64_C(0xf8a95fcf, 88747d94), -343, -84}, - {GRISU_UINT64_C(0x8a08f0f8, bf0f156b), -289, -68}, - {GRISU_UINT64_C(0x993fe2c6, d07b7fac), -236, -52}, - {GRISU_UINT64_C(0xaa242499, 697392d3), -183, -36}, - {GRISU_UINT64_C(0xbce50864, 92111aeb), -130, -20}, - {GRISU_UINT64_C(0xd1b71758, e219652c), -77, -4}, - {GRISU_UINT64_C(0xe8d4a510, 00000000), -24, 12}, - {GRISU_UINT64_C(0x813f3978, f8940984), 30, 28}, - {GRISU_UINT64_C(0x8f7e32ce, 7bea5c70), 83, 44}, - {GRISU_UINT64_C(0x9f4f2726, 179a2245), 136, 60}, - {GRISU_UINT64_C(0xb0de6538, 8cc8ada8), 189, 76}, - {GRISU_UINT64_C(0xc45d1df9, 42711d9a), 242, 92}, - {GRISU_UINT64_C(0xda01ee64, 1a708dea), 295, 108}, - {GRISU_UINT64_C(0xf209787b, b47d6b85), 348, 124}, - {GRISU_UINT64_C(0x865b8692, 5b9bc5c2), 402, 140}, - {GRISU_UINT64_C(0x952ab45c, fa97a0b3), 455, 156}, - {GRISU_UINT64_C(0xa59bc234, db398c25), 508, 172}, - {GRISU_UINT64_C(0xb7dcbf53, 54e9bece), 561, 188}, - {GRISU_UINT64_C(0xcc20ce9b, d35c78a5), 614, 204}, - {GRISU_UINT64_C(0xe2a0b5dc, 971f303a), 667, 220}, - {GRISU_UINT64_C(0xfb9b7cd9, a4a7443c), 720, 236}, - {GRISU_UINT64_C(0x8bab8eef, b6409c1a), 774, 252}, - {GRISU_UINT64_C(0x9b10a4e5, e9913129), 827, 268}, - {GRISU_UINT64_C(0xac2820d9, 623bf429), 880, 284}, - {GRISU_UINT64_C(0xbf21e440, 03acdd2d), 933, 300}, - {GRISU_UINT64_C(0xd433179d, 9c8cb841), 986, 316}, - {GRISU_UINT64_C(0xeb96bf6e, badf77d9), 1039, 332}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(16) = 54; -// nb elements (16): 41 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(17)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0x9faacf3d, f73609b1), -1030, -291}, - {GRISU_UINT64_C(0xdd95317f, 31c7fa1d), -974, -274}, - {GRISU_UINT64_C(0x99c10284, 4f94e0fb), -917, -257}, - {GRISU_UINT64_C(0xd5605fcd, cf32e1d7), -861, -240}, - {GRISU_UINT64_C(0x940f4613, ae5ed137), -804, -223}, - {GRISU_UINT64_C(0xcd795be8, 70516656), -748, -206}, - {GRISU_UINT64_C(0x8e938662, 882af53e), -691, -189}, - {GRISU_UINT64_C(0xc5dd4427, 1ad3cdba), -635, -172}, - {GRISU_UINT64_C(0x894bc396, ce5da772), -578, -155}, - {GRISU_UINT64_C(0xbe895233, 86091466), -522, -138}, - {GRISU_UINT64_C(0x843610cb, 4bf160cc), -465, -121}, - {GRISU_UINT64_C(0xb77ada06, 17e3bbcb), -409, -104}, - {GRISU_UINT64_C(0xfea126b7, d78186bd), -353, -87}, - {GRISU_UINT64_C(0xb0af48ec, 79ace837), -296, -70}, - {GRISU_UINT64_C(0xf5330471, 4d9265e0), -240, -53}, - {GRISU_UINT64_C(0xaa242499, 697392d3), -183, -36}, - {GRISU_UINT64_C(0xec1e4a7d, b69561a5), -127, -19}, - {GRISU_UINT64_C(0xa3d70a3d, 70a3d70a), -70, -2}, - {GRISU_UINT64_C(0xe35fa931, a0000000), -14, 15}, - {GRISU_UINT64_C(0x9dc5ada8, 2b70b59e), 43, 32}, - {GRISU_UINT64_C(0xdaf3f046, 51d47b4c), 99, 49}, - {GRISU_UINT64_C(0x97edd871, cfda3a57), 156, 66}, - {GRISU_UINT64_C(0xd2d80db0, 2aabd62c), 212, 83}, - {GRISU_UINT64_C(0x924d692c, a61be758), 269, 100}, - {GRISU_UINT64_C(0xcb090c80, 01ab551c), 325, 117}, - {GRISU_UINT64_C(0x8ce2529e, 2734bb1d), 382, 134}, - {GRISU_UINT64_C(0xc38413cf, 25e2d70e), 438, 151}, - {GRISU_UINT64_C(0x87aa9aff, 79042287), 495, 168}, - {GRISU_UINT64_C(0xbc4665b5, 96706115), 551, 185}, - {GRISU_UINT64_C(0x82a45b45, 0226b39d), 608, 202}, - {GRISU_UINT64_C(0xb54d5e4a, 127f59c8), 664, 219}, - {GRISU_UINT64_C(0xfb9b7cd9, a4a7443c), 720, 236}, - {GRISU_UINT64_C(0xae9672ab, a3d0c321), 777, 253}, - {GRISU_UINT64_C(0xf24a01a7, 3cf2dcd0), 833, 270}, - {GRISU_UINT64_C(0xa81f3014, 49ee8c70), 890, 287}, - {GRISU_UINT64_C(0xe950df20, 247c83fd), 946, 304}, - {GRISU_UINT64_C(0xa1e53af4, 6f801c53), 1003, 321}, - {GRISU_UINT64_C(0xe0accfa8, 75af45a8), 1059, 338}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(17) = 57; -// nb elements (17): 39 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(18)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0xc795830d, 75038c1e), -1027, -290}, - {GRISU_UINT64_C(0xad1c8eab, 5ee43b67), -967, -272}, - {GRISU_UINT64_C(0x96267c75, 35b763b5), -907, -254}, - {GRISU_UINT64_C(0x823c1279, 5db6ce57), -847, -236}, - {GRISU_UINT64_C(0xe1ebce4d, c7f16dfc), -788, -218}, - {GRISU_UINT64_C(0xc3f490aa, 77bd60fd), -728, -200}, - {GRISU_UINT64_C(0xa9f6d30a, 038d1dbc), -668, -182}, - {GRISU_UINT64_C(0x936b9fce, bb25c996), -608, -164}, - {GRISU_UINT64_C(0xffbbcfe9, 94e5c620), -549, -146}, - {GRISU_UINT64_C(0xddd0467c, 64bce4a1), -489, -128}, - {GRISU_UINT64_C(0xc06481fb, 9bcf8d3a), -429, -110}, - {GRISU_UINT64_C(0xa6dfbd9f, b8e5b88f), -369, -92}, - {GRISU_UINT64_C(0x90bd77f3, 483bb9ba), -309, -74}, - {GRISU_UINT64_C(0xfb158592, be068d2f), -250, -56}, - {GRISU_UINT64_C(0xd9c7dced, 53c72256), -190, -38}, - {GRISU_UINT64_C(0xbce50864, 92111aeb), -130, -20}, - {GRISU_UINT64_C(0xa3d70a3d, 70a3d70a), -70, -2}, - {GRISU_UINT64_C(0x8e1bc9bf, 04000000), -10, 16}, - {GRISU_UINT64_C(0xf684df56, c3e01bc7), 49, 34}, - {GRISU_UINT64_C(0xd5d238a4, abe98068), 109, 52}, - {GRISU_UINT64_C(0xb975d6b6, ee39e437), 169, 70}, - {GRISU_UINT64_C(0xa0dc75f1, 778e39d6), 229, 88}, - {GRISU_UINT64_C(0x8b865b21, 5899f46d), 289, 106}, - {GRISU_UINT64_C(0xf209787b, b47d6b85), 348, 124}, - {GRISU_UINT64_C(0xd1ef0244, af2364ff), 408, 142}, - {GRISU_UINT64_C(0xb616a12b, 7fe617aa), 468, 160}, - {GRISU_UINT64_C(0x9defbf01, b061adab), 528, 178}, - {GRISU_UINT64_C(0x88fcf317, f22241e2), 588, 196}, - {GRISU_UINT64_C(0xeda2ee1c, 7064130c), 647, 214}, - {GRISU_UINT64_C(0xce1de406, 42e3f4b9), 707, 232}, - {GRISU_UINT64_C(0xb2c71d5b, ca9023f8), 767, 250}, - {GRISU_UINT64_C(0x9b10a4e5, e9913129), 827, 268}, - {GRISU_UINT64_C(0x867f59a9, d4bed6c0), 887, 286}, - {GRISU_UINT64_C(0xe950df20, 247c83fd), 946, 304}, - {GRISU_UINT64_C(0xca5e89b1, 8b602368), 1006, 322}, - {GRISU_UINT64_C(0xaf87023b, 9bf0ee6b), 1066, 340}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(18) = 60; -// nb elements (18): 37 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(19)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0xf97ae3d0, d2446f25), -1024, -289}, - {GRISU_UINT64_C(0x873e4f75, e2224e68), -960, -270}, - {GRISU_UINT64_C(0x92a1958a, 7675175f), -897, -251}, - {GRISU_UINT64_C(0x9efa548d, 26e5a6e2), -834, -232}, - {GRISU_UINT64_C(0xac5d37d5, b79b6239), -771, -213}, - {GRISU_UINT64_C(0xbae0a846, d2195713), -708, -194}, - {GRISU_UINT64_C(0xca9cf1d2, 06fdc03c), -645, -175}, - {GRISU_UINT64_C(0xdbac6c24, 7d62a584), -582, -156}, - {GRISU_UINT64_C(0xee2ba6c0, 678b597f), -519, -137}, - {GRISU_UINT64_C(0x811ccc66, 8829b887), -455, -118}, - {GRISU_UINT64_C(0x8bfbea76, c619ef36), -392, -99}, - {GRISU_UINT64_C(0x97c560ba, 6b0919a6), -329, -80}, - {GRISU_UINT64_C(0xa48ceaaa, b75a8e2b), -266, -61}, - {GRISU_UINT64_C(0xb267ed19, 40f1c61c), -203, -42}, - {GRISU_UINT64_C(0xc16d9a00, 95928a27), -140, -23}, - {GRISU_UINT64_C(0xd1b71758, e219652c), -77, -4}, - {GRISU_UINT64_C(0xe35fa931, a0000000), -14, 15}, - {GRISU_UINT64_C(0xf684df56, c3e01bc7), 49, 34}, - {GRISU_UINT64_C(0x85a36366, eb71f041), 113, 53}, - {GRISU_UINT64_C(0x90e40fbe, ea1d3a4b), 176, 72}, - {GRISU_UINT64_C(0x9d174b2d, cec0e47b), 239, 91}, - {GRISU_UINT64_C(0xaa51823e, 34a7eedf), 302, 110}, - {GRISU_UINT64_C(0xb8a8d9bb, e123f018), 365, 129}, - {GRISU_UINT64_C(0xc83553c5, c8965d3d), 428, 148}, - {GRISU_UINT64_C(0xd910f7ff, 28069da4), 491, 167}, - {GRISU_UINT64_C(0xeb57ff22, fc0c795a), 554, 186}, - {GRISU_UINT64_C(0xff290242, c83396ce), 617, 205}, - {GRISU_UINT64_C(0x8a5296ff, e33cc930), 681, 224}, - {GRISU_UINT64_C(0x95f83d0a, 1fb69cd9), 744, 243}, - {GRISU_UINT64_C(0xa298f2c5, 01f45f43), 807, 262}, - {GRISU_UINT64_C(0xb049dc01, 6abc5e60), 870, 281}, - {GRISU_UINT64_C(0xbf21e440, 03acdd2d), 933, 300}, - {GRISU_UINT64_C(0xcf39e50f, eae16bf0), 996, 319}, - {GRISU_UINT64_C(0xe0accfa8, 75af45a8), 1059, 338}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(19) = 64; -// nb elements (19): 35 -static const GRISU_CACHE_STRUCT GRISU_CACHE_NAME(20)[] = { - {GRISU_UINT64_C(0xe61acf03, 3d1a45df), -1087, -308}, - {GRISU_UINT64_C(0x9becce62, 836ac577), -1020, -288}, - {GRISU_UINT64_C(0xd3515c28, 31559a83), -954, -268}, - {GRISU_UINT64_C(0x8f31cc09, 37ae58d3), -887, -248}, - {GRISU_UINT64_C(0xc2109436, 4dfb5637), -821, -228}, - {GRISU_UINT64_C(0x8380dea9, 3da4bc60), -754, -208}, - {GRISU_UINT64_C(0xb23867fb, 2a35b28e), -688, -188}, - {GRISU_UINT64_C(0xf18899b1, bc3f8ca2), -622, -168}, - {GRISU_UINT64_C(0xa3ab6658, 0d5fdaf6), -555, -148}, - {GRISU_UINT64_C(0xddd0467c, 64bce4a1), -489, -128}, - {GRISU_UINT64_C(0x964e858c, 91ba2655), -422, -108}, - {GRISU_UINT64_C(0xcbb41ef9, 79346bca), -356, -88}, - {GRISU_UINT64_C(0x8a08f0f8, bf0f156b), -289, -68}, - {GRISU_UINT64_C(0xbb127c53, b17ec159), -223, -48}, - {GRISU_UINT64_C(0xfd87b5f2, 8300ca0e), -157, -28}, - {GRISU_UINT64_C(0xabcc7711, 8461cefd), -90, -8}, - {GRISU_UINT64_C(0xe8d4a510, 00000000), -24, 12}, - {GRISU_UINT64_C(0x9dc5ada8, 2b70b59e), 43, 32}, - {GRISU_UINT64_C(0xd5d238a4, abe98068), 109, 52}, - {GRISU_UINT64_C(0x90e40fbe, ea1d3a4b), 176, 72}, - {GRISU_UINT64_C(0xc45d1df9, 42711d9a), 242, 92}, - {GRISU_UINT64_C(0x850fadc0, 9923329e), 309, 112}, - {GRISU_UINT64_C(0xb454e4a1, 79dd1877), 375, 132}, - {GRISU_UINT64_C(0xf46518c2, ef5b8cd1), 441, 152}, - {GRISU_UINT64_C(0xa59bc234, db398c25), 508, 172}, - {GRISU_UINT64_C(0xe070f78d, 3927556b), 574, 192}, - {GRISU_UINT64_C(0x98165af3, 7b2153df), 641, 212}, - {GRISU_UINT64_C(0xce1de406, 42e3f4b9), 707, 232}, - {GRISU_UINT64_C(0x8bab8eef, b6409c1a), 774, 252}, - {GRISU_UINT64_C(0xbd49d14a, a79dbc82), 840, 272}, - {GRISU_UINT64_C(0x80444b5e, 7aa7cf85), 907, 292}, - {GRISU_UINT64_C(0xadd57a27, d29339f6), 973, 312}, - {GRISU_UINT64_C(0xeb96bf6e, badf77d9), 1039, 332}, - }; -static const int GRISU_CACHE_MAX_DISTANCE(20) = 67; -// nb elements (20): 33 -static const int GRISU_CACHE_OFFSET = 308; diff --git a/js/src/v8-dtoa/utils.cc b/js/src/v8-dtoa/utils.cc deleted file mode 100644 index 4f626c907ae3..000000000000 --- a/js/src/v8-dtoa/utils.cc +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2006-2008 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include - -#include "v8.h" - -#include "platform.h" - -#include "sys/stat.h" - -namespace v8 { -namespace internal { - -void StringBuilder::AddString(const char* s) { - AddSubstring(s, StrLength(s)); -} - - -void StringBuilder::AddSubstring(const char* s, int n) { - ASSERT(!is_finalized() && position_ + n < buffer_.length()); - ASSERT(static_cast(n) <= strlen(s)); - memcpy(&buffer_[position_], s, n * kCharSize); - position_ += n; -} - - -// MOZ: This is not from V8. See DoubleToCString() for details. -void StringBuilder::AddInteger(int n) { - ASSERT(!is_finalized() && position_ < buffer_.length()); - // Get the number of digits. - int ndigits = 0; - int n2 = n; - do { - ndigits++; - n2 /= 10; - } while (n2); - - // Add the integer string backwards. - position_ += ndigits; - int i = position_; - do { - buffer_[--i] = '0' + (n % 10); - n /= 10; - } while (n); -} - - -void StringBuilder::AddPadding(char c, int count) { - for (int i = 0; i < count; i++) { - AddCharacter(c); - } -} - - -char* StringBuilder::Finalize() { - ASSERT(!is_finalized() && position_ < buffer_.length()); - buffer_[position_] = '\0'; - // Make sure nobody managed to add a 0-character to the - // buffer while building the string. - ASSERT(strlen(buffer_.start()) == static_cast(position_)); - position_ = -1; - ASSERT(is_finalized()); - return buffer_.start(); -} - -} } // namespace v8::internal diff --git a/js/src/v8-dtoa/utils.h b/js/src/v8-dtoa/utils.h deleted file mode 100644 index 366151cdba84..000000000000 --- a/js/src/v8-dtoa/utils.h +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2006-2008 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef V8_UTILS_H_ -#define V8_UTILS_H_ - -#include -#include - -namespace v8 { -namespace internal { - -// ---------------------------------------------------------------------------- -// General helper functions - -inline int StrLength(const char* string) { - size_t length = strlen(string); - ASSERT(length == static_cast(static_cast(length))); - return static_cast(length); -} - -// ---------------------------------------------------------------------------- -// Miscellaneous - -template -class Vector { - public: - Vector() : start_(NULL), length_(0) {} - Vector(T* data, int length) : start_(data), length_(length) { - ASSERT(length == 0 || (length > 0 && data != NULL)); - } - - // Returns the length of the vector. - int length() const { return length_; } - - // Returns the pointer to the start of the data in the vector. - T* start() const { return start_; } - - // Access individual vector elements - checks bounds in debug mode. - T& operator[](int index) const { - ASSERT(0 <= index && index < length_); - return start_[index]; - } - - inline Vector operator+(int offset) { - ASSERT(offset < length_); - return Vector(start_ + offset, length_ - offset); - } - - private: - T* start_; - int length_; -}; - - -// Helper class for building result strings in a character buffer. The -// purpose of the class is to use safe operations that checks the -// buffer bounds on all operations in debug mode. -class StringBuilder { - public: - - StringBuilder(char* buffer, int size) - : buffer_(buffer, size), position_(0) { } - - ~StringBuilder() { if (!is_finalized()) Finalize(); } - - // Add a single character to the builder. It is not allowed to add - // 0-characters; use the Finalize() method to terminate the string - // instead. - void AddCharacter(char c) { - ASSERT(c != '\0'); - ASSERT(!is_finalized() && position_ < buffer_.length()); - buffer_[position_++] = c; - } - - // Add an entire string to the builder. Uses strlen() internally to - // compute the length of the input string. - void AddString(const char* s); - - // Add the first 'n' characters of the given string 's' to the - // builder. The input string must have enough characters. - void AddSubstring(const char* s, int n); - - // Add an integer to the builder. - void AddInteger(int n); - - // Add character padding to the builder. If count is non-positive, - // nothing is added to the builder. - void AddPadding(char c, int count); - - // Finalize the string by 0-terminating it and returning the buffer. - char* Finalize(); - - private: - Vector buffer_; - int position_; - - bool is_finalized() const { return position_ < 0; } - - DISALLOW_IMPLICIT_CONSTRUCTORS(StringBuilder); -}; - - -// The type-based aliasing rule allows the compiler to assume that pointers of -// different types (for some definition of different) never alias each other. -// Thus the following code does not work: -// -// float f = foo(); -// int fbits = *(int*)(&f); -// -// The compiler 'knows' that the int pointer can't refer to f since the types -// don't match, so the compiler may cache f in a register, leaving random data -// in fbits. Using C++ style casts makes no difference, however a pointer to -// char data is assumed to alias any other pointer. This is the 'memcpy -// exception'. -// -// Bit_cast uses the memcpy exception to move the bits from a variable of one -// type of a variable of another type. Of course the end result is likely to -// be implementation dependent. Most compilers (gcc-4.2 and MSVC 2005) -// will completely optimize BitCast away. -// -// There is an additional use for BitCast. -// Recent gccs will warn when they see casts that may result in breakage due to -// the type-based aliasing rule. If you have checked that there is no breakage -// you can use BitCast to cast one pointer type to another. This confuses gcc -// enough that it can no longer see that you have cast one pointer type to -// another thus avoiding the warning. -template -inline Dest BitCast(const Source& source) { - // Compile time assertion: sizeof(Dest) == sizeof(Source) - // A compile error here means your Dest and Source have different sizes. - typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1]; - - Dest dest; - memcpy(&dest, &source, sizeof(dest)); - return dest; -} - -} } // namespace v8::internal - -#endif // V8_UTILS_H_ diff --git a/js/src/v8-dtoa/v8-dtoa.cc b/js/src/v8-dtoa/v8-dtoa.cc deleted file mode 100644 index 7ea3818047b8..000000000000 --- a/js/src/v8-dtoa/v8-dtoa.cc +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2010 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// MOZ: this file was called dtoa.cc, but that clashed in the build with -// the file dtoa.c in SpiderMonkey, so this file was renamed v8-dtoa.cc. - -#include - -#include "v8.h" -#include "dtoa.h" -#include "double.h" -#include "fast-dtoa.h" - -namespace v8 { -namespace internal { - -bool DoubleToAscii(double v, DtoaMode mode, int requested_digits, - Vector buffer, int* sign, int* length, int* point) { - ASSERT(!Double(v).IsSpecial()); - ASSERT(mode == DTOA_SHORTEST || requested_digits >= 0); - - if (Double(v).Sign() < 0) { - *sign = 1; - v = -v; - } else { - *sign = 0; - } - - if (v == 0) { - buffer[0] = '0'; - buffer[1] = '\0'; - *length = 1; - *point = 1; - return true; - } - - if (mode == DTOA_PRECISION && requested_digits == 0) { - buffer[0] = '\0'; - *length = 0; - return true; - } - - switch (mode) { - case DTOA_SHORTEST: - return FastDtoa(v, buffer, length, point); - case DTOA_FIXED: - // MOZ: should never happen. - //return FastFixedDtoa(v, requested_digits, buffer, length, point); - default: - break; - } - return false; -} - -} } // namespace v8::internal diff --git a/js/src/v8-dtoa/v8.h b/js/src/v8-dtoa/v8.h deleted file mode 100644 index 48eb46bea634..000000000000 --- a/js/src/v8-dtoa/v8.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2006-2008 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// -// Top include for all V8 .cc files. -// - -#ifndef V8_V8_H_ -#define V8_V8_H_ - -// V8 only uses DEBUG, but included external files -// may use NDEBUG - make sure they are consistent. -#if defined(DEBUG) && defined(NDEBUG) -#error both DEBUG and NDEBUG are set -#endif - -// Basic includes -#include "include-v8.h" -#include "globals.h" -#include "checks.h" -#include "utils.h" - -#include "platform.h" - -namespace i = v8::internal; - -#endif // V8_V8_H_ diff --git a/mfbt/Makefile.in b/mfbt/Makefile.in index 4755f42632df..ebf4d6de8993 100644 --- a/mfbt/Makefile.in +++ b/mfbt/Makefile.in @@ -57,7 +57,8 @@ include $(srcdir)/exported_headers.mk # sources.mk defines the source files built for mfbt. It is included by mfbt # itself and by the JS engine, which, when built standalone, must do the work # to build mfbt sources itself. -include $(srcdir)/sources.mk +MFBT_ROOT = $(srcdir) +include $(MFBT_ROOT)/sources.mk DEFINES += -DIMPL_MFBT diff --git a/mfbt/sources.mk b/mfbt/sources.mk index 2fdfc22d0b5a..884a71701c1b 100644 --- a/mfbt/sources.mk +++ b/mfbt/sources.mk @@ -1,4 +1,24 @@ +ifndef MFBT_ROOT +$(error Before including this file, you must define MFBT_ROOT to point to \ +the MFBT source directory) +endif + CPPSRCS += \ Assertions.cpp \ HashFunctions.cpp \ - $(NULL) \ No newline at end of file + $(NULL) + +# Imported double-conversion sources. +VPATH += $(MFBT_ROOT)/double-conversion \ + $(NULL) + +CPPSRCS += \ + bignum-dtoa.cc \ + bignum.cc \ + cached-powers.cc \ + diy-fp.cc \ + double-conversion.cc \ + fast-dtoa.cc \ + fixed-dtoa.cc \ + strtod.cc \ + $(NULL)