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 Q.of_string #72

Merged
merged 8 commits into from
Sep 21, 2020
Merged

Fix Q.of_string #72

merged 8 commits into from
Sep 21, 2020

Conversation

hhugo
Copy link
Contributor

@hhugo hhugo commented Sep 15, 2020

  • exponent are parsed in decimal base
  • the base prefix is case insensitive (allowing 0x and 0X)
  • fix parsing of hexadecimal with radix
  • reduce the number of string allocation

- exponent are parsed in decimal base
- the base prefix is case insensitive (allow 0x and 0X)
- fix parsing of hexadecimal with radix
- reduce the number of string allocation
@hhugo
Copy link
Contributor Author

hhugo commented Sep 15, 2020

Fix #65

@hhugo
Copy link
Contributor Author

hhugo commented Sep 15, 2020

Still need to add regression tests for all fixes

@ghilesZ
Copy link
Contributor

ghilesZ commented Sep 15, 2020

Well played

@hhugo
Copy link
Contributor Author

hhugo commented Sep 15, 2020

This is ready for review.
@ghilesZ Would you want do it ?

@ghilesZ
Copy link
Contributor

ghilesZ commented Sep 15, 2020

Sure. I'll do it probably tomorrow

Copy link
Contributor

@ghilesZ ghilesZ left a comment

Choose a reason for hiding this comment

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

This looks correct AFAIU. However, the use of the Int module (l.462 : Int.abs) would break retrocompatibity with OCaml versions before 4.08 which is probably too much. However it can easilly be removed as you explicitely check for the sign of abs anyway just after. As a minor detail, i'm unsure why the parse_sign take an exra argument i since is is always called (once) with i=0. This could be simplified.

@ghilesZ
Copy link
Contributor

ghilesZ commented Sep 16, 2020

This makes me think that the whole test if String.length s < i + 1 in parse_sign is unnecessary as it would only be true when s is the empty string (in which case we do not enter the of_scientific_notation function). But i might be wrong.

@ghilesZ
Copy link
Contributor

ghilesZ commented Sep 16, 2020

Also, just to be picky the String.contains s "/" line is a bit redundant with the String.index s '/' as it goes through the string twice, and sadly using index_opt would break compatibility with OCaml < 4.05 (I'm unsure what is Zarith's policy about retro-compatibility but if i trust the README.md is should be compatible whith 3.12). A try ... with Not_found -> of_scientific_notation ... can be the solution.

@xavierleroy
Copy link
Contributor

Concerning compatibility with old versions of OCaml: version 4.05 is a reasonable base line, as it's the OCaml version found in Debian stable, one of the most conservative free software distributions out there. So, String.index_opt is OK, but the Int module is not.

@hhugo
Copy link
Contributor Author

hhugo commented Sep 16, 2020

I've restored compatibility with ocaml 3.12
I've removed duplication between String.contains and String.index
The additional check in parse_sign is not necessary but require knowledge about the call sites. I find it easier to review this way and more future proof (similar to the logic related to num_digits)

Copy link
Contributor

@ghilesZ ghilesZ left a comment

Choose a reason for hiding this comment

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

I think this is now ready for merge

Copy link
Contributor

@xavierleroy xavierleroy left a comment

Choose a reason for hiding this comment

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

A couple of style comments below. I'm willing to merge on behalf of @ghilesZ's review and because the current implementation of of_string is not right.

q.ml Outdated Show resolved Hide resolved
q.ml Outdated Show resolved Hide resolved
@antoinemine
Copy link
Collaborator

I'm also OK to merge.
Just to be clear : the implementation will magically support underscores as soon as Z.of_string (& co.) support it?

hhugo and others added 2 commits September 21, 2020 08:09
Co-authored-by: Xavier Leroy <xavierleroy@users.noreply.github.com>
@hhugo
Copy link
Contributor Author

hhugo commented Sep 21, 2020

Just to be clear : the implementation will magically support underscores as soon as Z.of_string (& co.) support it?

I've just created #75 to support underscores

@xavierleroy
Copy link
Contributor

Looks good to me. Let's merge!

@xavierleroy xavierleroy merged commit 54ecbeb into ocaml:master Sep 21, 2020
@hhugo hhugo deleted the fix-of-string branch September 21, 2020 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants