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

lossless float support #98

Merged
merged 8 commits into from
May 21, 2024
Merged

lossless float support #98

merged 8 commits into from
May 21, 2024

Conversation

samuelcolvin
Copy link
Member

@samuelcolvin samuelcolvin commented May 20, 2024

fix #80.

Example usage:

import jiter

f = jiter.from_json(b'123.456789123456789e45', lossless_floats=True)
assert isinstance(f, jiter.LosslessFloat)
assert 123e45 < float(f) < 124e45
assert f.as_decimal() == Decimal('1.23456789123456789E+47')
assert bytes(f) == b'123.456789123456789e45'
assert str(f) == '123.456789123456789e45'
assert repr(f) == 'LosslessFloat(123.456789123456789e45)'

@samuelcolvin samuelcolvin changed the title Full float info lossless float support May 20, 2024
Copy link

codspeed-hq bot commented May 21, 2024

CodSpeed Performance Report

Merging #98 will not alter performance

Comparing py-float (9ed4360) with main (1fbedbf)

Summary

✅ 73 untouched benchmarks

crates/jiter-python/Cargo.toml Outdated Show resolved Hide resolved
crates/jiter-python/jiter.pyi Show resolved Hide resolved
crates/jiter-python/jiter.pyi Outdated Show resolved Hide resolved
crates/jiter/Cargo.toml Outdated Show resolved Hide resolved
crates/jiter/src/number_decoder.rs Outdated Show resolved Hide resolved
crates/jiter/src/parse.rs Show resolved Hide resolved
crates/jiter/src/py_lossless_float.rs Outdated Show resolved Hide resolved
Comment on lines +32 to +37
let f = jiter
.next_float()
.map_err(|e| PyValueError::new_err(e.description(&jiter)))?;
jiter
.finish()
.map_err(|e| PyValueError::new_err(e.description(&jiter)))?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is quite big brain 🧠. Is it worth considering a lower-level function to just try to parse the float as a number range and fail if it doesn't successfully consume the whole string?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's good as is.

@samuelcolvin samuelcolvin enabled auto-merge (squash) May 21, 2024 20:02
@samuelcolvin samuelcolvin merged commit e78c3fa into main May 21, 2024
18 checks passed
@samuelcolvin samuelcolvin deleted the py-float branch May 21, 2024 20:08
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.

Retain full float information
2 participants