Should JavaScript Add Support for Large Numbers?

0
11
Asked By CleverCat92 On

As software and applications increasingly handle vast amounts of data, many programming languages have begun integrating native support for large numbers, similar to what Python has implemented. I'm currently developing an open-source P2P app for calling, texting, and data sharing using Node.js, and each peer is assigned a unique ID based on a hash of their public ed25519 key. Initially, I thought it would be neat to use base-10 for these peer IDs to maintain compatibility with regular phone numbers. However, I ran into issues with ID collisions. I switched to base-16, but that led to a usability nightmare since the transition went from a numpad to a full keyboard, leaving many keys unused. My latest attempt was to use a 16-character base-36 string, but Node.js doesn't seem to handle those well, and it's causing major problems. With the rise of AI and big data, the need for robust support for large numbers is more critical than ever in JavaScript, not just for my specific project but for the future of innovation in general. We can't ignore these large numbers just because our current tools struggle with them!

5 Answers

Answered By TechieTrendsetter83 On

JavaScript offers both BigInts for numerical calculations and strings for everything else, so it seems like the tools are there. Not much of a big deal if you know when to use each!

Answered By CodeWhisperer12 On

Your issue might actually stem from using parseInt. It's doubtful that anyone will update it to handle BigInt, so you might want to consider writing a custom solution. The comparison with Python shows that while Python can easily handle big numbers and different bases, JavaScript is still catching up in that aspect.

Answered By DataGuru21 On

JavaScript does have support for large integers through BigInt, but keep in mind that BigInt doesn't directly handle base-36. It barely supports base-16 either. Other languages like Python can manage this better right out of the box. JavaScript’s capabilities are impressive, but the lack of extensive number support may drive developers to seek alternatives.

Answered By NumCruncher54 On

If you really need to perform math operations, then BigInts are useful, but for IDs and hashes, just use strings. For cryptographic functions, you should be using typed arrays or buffers instead of relying on number types.

Answered By SkepticalDev99 On

It sounds like you're trying to force a UUID into a number format, which is a bit unnecessary. Just stick with using strings; Node.js can easily handle long strings without any issues.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.