Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: #3342 hexadecimal input not turned into a bigint #3348

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

josdejong
Copy link
Owner

@@ -48,8 +74,16 @@ export function isIntegerStr (str) {
* @returns {'number' | 'BigNumber' | 'bigint' | 'Fraction'}
*/
export function safeNumberType (numberStr, config) {
if (config.number === 'bigint' && !isIntegerStr(numberStr)) {
return config.numberFallback
if (config.number === 'bigint') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following definition of safeNumberType passes all tests:

export function safeNumberType (numberStr, config) {
  if (config.number === 'bigint') {
    try {
      BigInt(numberStr)
    } catch {
      return config.numberFallback
    }
  }

  return config.number
}

If we adopted this, we would not need the three new "isXXXStr" functions, and we would be future-proofing mathjs against any other integer notations. Would you like to switch to this? If so, will you do the refactoring or would you like me to? Just let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants