-
-
Notifications
You must be signed in to change notification settings - Fork 15
FIX: SLEEF migration to 4.0 #240
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
SwayamInSync
wants to merge
11
commits into
numpy:main
Choose a base branch
from
SwayamInSync:sleef-migration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
259225c
adding more dep
SwayamInSync b3a7a1e
updaed the meson requirements
SwayamInSync 74fa409
fixing operation behaviours
SwayamInSync 568225d
link sleef-build for sleefquad
SwayamInSync bab4d0a
upgrade to ubuntu24 in BE
SwayamInSync dde614b
enable SSE
SwayamInSync 1ec36d6
--config RELEASE for tlfloat
SwayamInSync 3d37460
adding related tests
SwayamInSync 7db9e43
fix at commit than branch
SwayamInSync e5c6361
mic drop
SwayamInSync c918666
resolving build warnings
SwayamInSync File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,12 +134,17 @@ NumPyOS_ascii_strtoq(const char *s, QuadBackendType backend, quad_value *out_val | |
| } | ||
| } | ||
|
|
||
| // Set NaN value (sign is ignored for NaN) | ||
| // Set NaN value with sign preserved | ||
| if (backend == BACKEND_SLEEF) { | ||
| out_value->sleef_value = QUAD_PRECISION_NAN; | ||
| Sleef_quad nan_val = QUAD_PRECISION_NAN; | ||
| // Apply sign to NaN (negative NaN has sign bit set) | ||
| if (sign < 0) { | ||
| nan_val = Sleef_negq1(nan_val); | ||
| } | ||
| out_value->sleef_value = nan_val; | ||
| } | ||
| else { | ||
| out_value->longdouble_value = nanl(""); | ||
| out_value->longdouble_value = sign < 0 ? -nanl("") : nanl(""); | ||
| } | ||
|
|
||
| if (endptr) { | ||
|
|
@@ -157,15 +162,103 @@ int cstring_to_quad(const char *str, QuadBackendType backend, quad_value *out_va | |
| char **endptr, bool require_full_parse) | ||
| { | ||
| if(backend == BACKEND_SLEEF) { | ||
| out_value->sleef_value = Sleef_strtoq(str, endptr); | ||
| // SLEEF 4.0's Sleef_strtoq doesn't properly set endptr to indicate | ||
| // where parsing stopped. It always sets endptr to the end of the string. | ||
| // We need to manually validate and track the parse position. | ||
|
|
||
| const char *p = str; | ||
|
|
||
| // Skip leading whitespace | ||
| while (ascii_isspace(*p)) { | ||
| p++; | ||
| } | ||
|
|
||
| // Track start of number (after whitespace) | ||
| const char *num_start = p; | ||
|
|
||
| // Handle optional sign | ||
| if (*p == '+' || *p == '-') { | ||
| p++; | ||
| } | ||
|
|
||
| // Must have at least one digit or decimal point followed by digit | ||
| int has_digits = 0; | ||
| int has_decimal = 0; | ||
|
|
||
| // Parse integer part | ||
| while (ascii_isdigit(*p)) { | ||
| has_digits = 1; | ||
| p++; | ||
| } | ||
|
|
||
| // Parse decimal point and fractional part | ||
| if (*p == '.') { | ||
| has_decimal = 1; | ||
| p++; | ||
| while (ascii_isdigit(*p)) { | ||
| has_digits = 1; | ||
| p++; | ||
| } | ||
| } | ||
|
|
||
| // Must have at least one digit somewhere | ||
| if (!has_digits) { | ||
| if (endptr) *endptr = (char *)str; | ||
| return -1; | ||
| } | ||
|
|
||
| // Parse optional exponent | ||
| if (*p == 'e' || *p == 'E') { | ||
| const char *exp_start = p; | ||
| p++; | ||
|
|
||
| // Optional sign in exponent | ||
| if (*p == '+' || *p == '-') { | ||
| p++; | ||
| } | ||
|
|
||
| // Must have at least one digit in exponent | ||
| if (!ascii_isdigit(*p)) { | ||
| // Invalid exponent, backtrack | ||
| p = exp_start; | ||
| } else { | ||
| while (ascii_isdigit(*p)) { | ||
| p++; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Now p points to where valid parsing ends | ||
| // SLEEF 4.0's Sleef_strtoq has a bug where it doesn't properly stop at whitespace | ||
| // or other delimiters. We need to create a null-terminated substring. | ||
| size_t len = p - str; | ||
| char *temp = (char *)malloc(len + 1); | ||
| if (!temp) { | ||
| if (endptr) *endptr = (char *)str; | ||
| return -1; | ||
| } | ||
| memcpy(temp, str, len); | ||
| temp[len] = '\0'; | ||
|
|
||
| // Call Sleef_strtoq with the bounded string | ||
| char *sleef_endptr; | ||
| out_value->sleef_value = Sleef_strtoq(temp, &sleef_endptr); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is pretty subuptimal :( Consider refactoring all the code you added here into a function even if there's only one caller, since it's pretty distracting here inline in this function. |
||
| free(temp); | ||
|
|
||
| // Set endptr to our calculated position | ||
| if (endptr) { | ||
| *endptr = (char *)p; | ||
| } | ||
|
|
||
| } else { | ||
| out_value->longdouble_value = strtold(str, endptr); | ||
| } | ||
| if(*endptr == str) | ||
|
|
||
| if(endptr && *endptr == str) | ||
| return -1; // parse error - nothing was parsed | ||
|
|
||
| // If full parse is required | ||
| if(require_full_parse && **endptr != '\0') | ||
| if(require_full_parse && endptr && **endptr != '\0') | ||
| return -1; // parse error - characters remain to be converted | ||
|
|
||
| return 0; // success | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| [wrap-git] | ||
| directory=sleef | ||
| url=https://github.com/shibatch/sleef.git | ||
| revision=3.8 | ||
| revision=43a0252ba9331adc7fb10755021f802863678c38 | ||
| patch_directory=sleef | ||
|
|
||
| [provide] | ||
| sleef = sleef_dep | ||
| sleefquad = sleefquad_dep | ||
| sleefquad = sleefquad_dep | ||
| tlfloat = tlfloat_dep |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kinda seems like a SLEEF bug you should report (even if they'll ignore it).