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

Big_int and Num "of_string" functions do not work with hexadecimal literals #4323

Closed
vicuna opened this issue Jun 22, 2007 · 7 comments
Closed

Comments

@vicuna
Copy link

vicuna commented Jun 22, 2007

Original bug ID: 4323
Reporter: zack
Assigned to: @gasche
Status: closed (set by @xavierleroy on 2015-12-11T18:25:35Z)
Resolution: fixed
Priority: normal
Severity: feature
Version: 3.09.2
Fixed in version: 4.02.0+dev
Category: ~DO NOT USE (was: OCaml general)
Tags: junior_job
Has duplicate: #3599
Related to: #6296

Bug description

It is possible to build integers from hexadecimal literals (with the convention that they start with "0x") for integers in Pervasives, Int32, and Int64. However it is not possible to do the same for integers in Big_int or Num. Please add this possibility.

File attachments

@vicuna
Copy link
Author

vicuna commented Jul 31, 2013

Comment author: @lpw25

Just a note to point out that zoep has attached a patch for this request

@vicuna
Copy link
Author

vicuna commented Jul 31, 2013

Comment author: @gasche

The code looks good, but I'm a bit wary of having to review sys_nat_of_string to make sure it didn't somehow make base-10 assumptions. I assume this would be catched rather quickly by testing; would it be possible to add relevant tests in testsuite/tests/lib-num to exercise the new code paths?

@vicuna
Copy link
Author

vicuna commented Aug 1, 2013

Comment author: @gasche

After having a closer look, sys_nat_of_string is in fact fine but should be updated, along with base_digit_of_char (still in nat.ml), to accept the lexical conventions of OCaml integer literals ( http://caml.inria.fr/pub/docs/manual-ocaml/lex.html#integer-literal ):

  • both lowercase and uppercase letters should be accepted in hexa (currently only uppercase)
  • underscores in the number should be ignored (at any base)

@vicuna
Copy link
Author

vicuna commented Aug 1, 2013

Comment author: zoep

I made a new patch based on gasche's notes and the lexical conventions described in the link.

  • Underscore characters are ignored anywhere in the number, except before the first digit
  • Lowercase letters are accepted in hexa
  • Both uppercase and lowercase characters are accepted in base prefixes, instead of just lowercase in the previous patch
  • Some simple tests were added

@vicuna
Copy link
Author

vicuna commented Aug 1, 2013

Comment author: @gasche

This new patch looks fine, thank you!

@vicuna
Copy link
Author

vicuna commented Aug 4, 2013

Comment author: @gasche

The patch is now committed in trunk, thanks! If you wish to appear in the changelog under a different name than "zoep", this can still be changed.

(To keep in mind for future patch submitters: at some point we pick a name to give credit to.)

@vicuna
Copy link
Author

vicuna commented Aug 4, 2013

Comment author: zoep

Happy to see that! Also I would prefer if you could use my real name, Zoe Paraskevopoulou, instead of zoep. Thanks!

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

No branches or pull requests

2 participants