René's URL Explorer Experiment


Title: fix(maths): prevent float rounding error in numberOfDigitsUsingLog for large safe integers by SaifAli-S · Pull Request #2029 · TheAlgorithms/JavaScript · GitHub

Open Graph Title: fix(maths): prevent float rounding error in numberOfDigitsUsingLog for large safe integers by SaifAli-S · Pull Request #2029 · TheAlgorithms/JavaScript

X Title: fix(maths): prevent float rounding error in numberOfDigitsUsingLog for large safe integers by SaifAli-S · Pull Request #2029 · TheAlgorithms/JavaScript

Description: Describe your change: Add an algorithm? Fix a bug or typo in an existing algorithm? Documentation change? Maths/NumberOfDigits.js previously implemented numberOfDigitsUsingLog as Math.floor(Math.log10(Math.abs(n))) + 1. Because IEEE 754 double precision floats have a 53-bit mantissa, Math.log10(999999999999999) ($10^{15}-1$) evaluates to 15 instead of 14.9999.... This caused numberOfDigitsUsingLog(999999999999999) to return 16 instead of 15. Since $999999999999999 < \text{Number.MAX_SAFE_INTEGER}$ ($9007199254740991$), this was an unexpected calculation error for a safe integer. This PR fixes the precision issue by checking power-of-ten bounds (Math.pow(10, digits - 1) and Math.pow(10, digits)), adds input validation (Number.isFinite), and adds unit test cases for $10^{15}-1$, $10^{15}$, and $10^{15}+1$ in Maths/test/NumberOfDigits.test.js. Checklist: I have read CONTRIBUTING.md. This pull request is all my own work -- I have not plagiarized. I know that pull requests will not be merged if they fail the automated tests. This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms. All new JavaScript files are placed inside an existing directory. All filenames should use the UpperCamelCase (PascalCase) style. There should be no spaces in filenames. All new algorithms have a URL in their comments that points to Wikipedia or another similar explanation.

Open Graph Description: Describe your change: Add an algorithm? Fix a bug or typo in an existing algorithm? Documentation change? Maths/NumberOfDigits.js previously implemented numberOfDigitsUsingLog as Math.floor(Ma...

X Description: Describe your change: Add an algorithm? Fix a bug or typo in an existing algorithm? Documentation change? Maths/NumberOfDigits.js previously implemented numberOfDigitsUsingLog as Math.floor(Ma...

Opengraph URL: https://github.com/TheAlgorithms/JavaScript/pull/2029

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:1d5ea6a6-edc5-80eb-36cd-455766a52c97
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idA332:213839:3261C76:4066DC9:6B01C92F
html-safe-nonce725f499c0bf5ebe77c498245305065fee560909483afc72f9674fee5698ab5c2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzMyOjIxMzgzOTozMjYxQzc2OjQwNjZEQzk6NkIwMUM5MkYiLCJ2aXNpdG9yX2lkIjoiNTM1OTkyNzc5MDU3NTY2NzUwNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac7cfae871ada8921a9d4cee2f9625bbb81fadcdf357868c6579b612fe15157095
hovercard-subject-tagpull_request:5300882591
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/TheAlgorithms/JavaScript/pull/2029/files
twitter:imagehttps://avatars.githubusercontent.com/u/233760032?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/233760032?s=400&v=4
og:image:altDescribe your change: Add an algorithm? Fix a bug or typo in an existing algorithm? Documentation change? Maths/NumberOfDigits.js previously implemented numberOfDigitsUsingLog as Math.floor(Ma...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/TheAlgorithms/JavaScript git https://github.com/TheAlgorithms/JavaScript.git
octolytics-dimension-user_id20487725
octolytics-dimension-user_loginTheAlgorithms
octolytics-dimension-repository_id97086543
octolytics-dimension-repository_nwoTheAlgorithms/JavaScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id97086543
octolytics-dimension-repository_network_root_nwoTheAlgorithms/JavaScript
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/TheAlgorithms/JavaScript/pull/2029/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FTheAlgorithms%2FJavaScript%2Fpull%2F2029%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FTheAlgorithms%2FJavaScript%2Fpull%2F2029%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=TheAlgorithms%2FJavaScript
Reloadhttps://github.com/TheAlgorithms/JavaScript/pull/2029/files
Reloadhttps://github.com/TheAlgorithms/JavaScript/pull/2029/files
Reloadhttps://github.com/TheAlgorithms/JavaScript/pull/2029/files
TheAlgorithmshttps://github.com/TheAlgorithms
JavaScripthttps://github.com/TheAlgorithms/JavaScript
Codehttps://github.com/TheAlgorithms/JavaScript
Issues22 (22)https://github.com/TheAlgorithms/JavaScript/issues
Pull requests293 (293)https://github.com/TheAlgorithms/JavaScript/pulls
Actionshttps://github.com/TheAlgorithms/JavaScript/actions
Projectshttps://github.com/TheAlgorithms/JavaScript/projects
Wikihttps://github.com/TheAlgorithms/JavaScript/wiki
Security and qualityhttps://github.com/TheAlgorithms/JavaScript/security
Insightshttps://github.com/TheAlgorithms/JavaScript/insights
Sign up for GitHub https://github.com/signup?return_to=%2FTheAlgorithms%2FJavaScript%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FTheAlgorithms%2FJavaScript%2Fissues%2Fnew%2Fchoose
SaifAli-Shttps://github.com/SaifAli-S
TheAlgorithms:masterhttps://github.com/TheAlgorithms/JavaScript/tree/master
SaifAli-S:fix-number-of-digits-precisionhttps://github.com/SaifAli-S/JavaScript/tree/fix-number-of-digits-precision
Conversation 1 https://github.com/TheAlgorithms/JavaScript/pull/2029
Commits 1 https://github.com/TheAlgorithms/JavaScript/pull/2029/commits
Checks 3 https://github.com/TheAlgorithms/JavaScript/pull/2029/checks
Files changed https://github.com/TheAlgorithms/JavaScript/pull/2029/files
Please reload this pagehttps://github.com/TheAlgorithms/JavaScript/pull/2029/files
fix(maths): prevent float rounding error in numberOfDigitsUsingLog for large safe integers https://github.com/TheAlgorithms/JavaScript/pull/2029/files#top
Show all changes 1 commit https://github.com/TheAlgorithms/JavaScript/pull/2029/files
44286c5 fix(maths): prevent float rounding error in numberOfDigitsUsingLog fo… SaifAli-S Nov 13, 2026 https://github.com/TheAlgorithms/JavaScript/pull/2029/commits/44286c5c3c592d9f09ece28f76cba71e90b9e12c
Clear filters https://github.com/TheAlgorithms/JavaScript/pull/2029/files
Please reload this pagehttps://github.com/TheAlgorithms/JavaScript/pull/2029/files
Please reload this pagehttps://github.com/TheAlgorithms/JavaScript/pull/2029/files
NumberOfDigits.js https://github.com/TheAlgorithms/JavaScript/pull/2029/files#diff-bbbb9a1a93f2d684115df3a8e57ebb13247881d6943d33df03115321e8c083fd
NumberOfDigits.test.js https://github.com/TheAlgorithms/JavaScript/pull/2029/files#diff-1fab4048ee55853497b79bd214ca2abd86143e68d079b7f52e343ae78b68f87f
https://github.com/TheAlgorithms/JavaScript/blob/master/.github/CODEOWNERS#L1
Maths/NumberOfDigits.jshttps://github.com/TheAlgorithms/JavaScript/pull/2029/files#diff-bbbb9a1a93f2d684115df3a8e57ebb13247881d6943d33df03115321e8c083fd
View file https://github.com/TheAlgorithms/JavaScript/blob/44286c5c3c592d9f09ece28f76cba71e90b9e12c/Maths/NumberOfDigits.js
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/TheAlgorithms/JavaScript/pull/2029/{{ revealButtonHref }}
https://github.com/TheAlgorithms/JavaScript/pull/2029/files#diff-bbbb9a1a93f2d684115df3a8e57ebb13247881d6943d33df03115321e8c083fd
https://github.com/TheAlgorithms/JavaScript/pull/2029/files#diff-bbbb9a1a93f2d684115df3a8e57ebb13247881d6943d33df03115321e8c083fd
https://github.com/TheAlgorithms/JavaScript/blob/master/.github/CODEOWNERS#L1
Maths/test/NumberOfDigits.test.jshttps://github.com/TheAlgorithms/JavaScript/pull/2029/files#diff-1fab4048ee55853497b79bd214ca2abd86143e68d079b7f52e343ae78b68f87f
View file https://github.com/TheAlgorithms/JavaScript/blob/44286c5c3c592d9f09ece28f76cba71e90b9e12c/Maths/test/NumberOfDigits.test.js
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/TheAlgorithms/JavaScript/pull/2029/{{ revealButtonHref }}
https://github.com/TheAlgorithms/JavaScript/pull/2029/files#diff-1fab4048ee55853497b79bd214ca2abd86143e68d079b7f52e343ae78b68f87f
Please reload this pagehttps://github.com/TheAlgorithms/JavaScript/pull/2029/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.