Skip to content

Bikeshedding: BigInt.sqrt/cbrt vs. BigInt.isqrt/icbrt #26

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

Open
js-choi opened this issue Apr 29, 2025 · 4 comments
Open

Bikeshedding: BigInt.sqrt/cbrt vs. BigInt.isqrt/icbrt #26

js-choi opened this issue Apr 29, 2025 · 4 comments
Labels
question Further information is requested

Comments

@js-choi
Copy link
Collaborator

js-choi commented Apr 29, 2025

Most programming languages that include the integer square root use the name isqrt instead of sqrt. Some of them do use sqrt for integer square roots.

  • isqrt in generic namespace: Common Lisp, Crystal, Julia, Maple, PARI/GP*, Python, Racket*, SageMath, Scheme*, Tcl
  • isqrt in integer namespace/class: Rust
  • sqrt in integer namespace/class: Chapel, Java, Ruby, Zig

(Languages marked with * spell out isqrt using words like integer-sqrt.)

Notably, if we name the BigInt root functions BigInt.isqrt/icbrt instead of BigInt.sqrt/cbrt, then this would point towards also including a Math.isqrt/icbrt for numbers.

  • Should we name the BigInt root functions BigInt.sqrt/cbrt vs. BigInt.isqrt/icbrt?
  • If we do go with BigInt.isqrt/icbrt, then, in a future proposal (not this one), should we consider Math.isqrt/icbrt for numbers?

I would personally like integer square roots to consistently be isqrt across both bigints (BigInt.isqrt) and numbers (Number.isqrt). If integer square roots are useful on bigints, then they'd be useful on integer numbers too.

CC: @bakkot, @waldemarhorwat, @ljharb

@js-choi js-choi added the question Further information is requested label Apr 29, 2025
@ljharb
Copy link
Member

ljharb commented Apr 29, 2025

the "i" is already implied, pretty explicitly, by the "Int" in "BigInt" - i don't see the point in including it here.

@Rudxain
Copy link

Rudxain commented Apr 30, 2025

To avoid repeating myself: rust-lang/rust#89273 (comment)

@ljharb
Copy link
Member

ljharb commented Apr 30, 2025

It's already an int - it can't ever mean anything other than "isqrt". JS only has Number and BigInt, so that comment's discussion of float types doesn't apply.

@js-choi
Copy link
Collaborator Author

js-choi commented Apr 30, 2025

I think the key question here is if we would later add an integer square root function for numbers, Math.isqrt.

If yes, then we probably should go with BigInt.isqrt, to match Math.isqrt.
If not, then we probably should go with BigInt.sqrt.

I’m personally mildly inclined toward ”no, we won’t ever add a Math.isqrt, but it’s still worth discussing a little, since it still may be useful to have a faster version of Math.sqrt then Math.floor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants