Fix: Replace unavailable snprintf with Rust formatting on Windows#133
Fix: Replace unavailable snprintf with Rust formatting on Windows#133bardo84 wants to merge 2 commits intorunmat-org:mainfrom
Conversation
|
Someone is attempting to deploy a commit to the Dystr Team on Vercel. A member of the Team first needs to authorize it. |
|
@bardo84 -- thanks for submitting this! I've cleared the CI/CD runners to run so the test suite can be evaluated on all platforms for the changeset. Can you please resolve the callouts provided by cursor BugBot? They generally seem like good catches. |
a66c4a7 to
e0ff33a
Compare
| fn format_with_spec(value: f64, spec: char, precision: Option<usize>) -> String { | ||
| match spec { | ||
| 'e' => format!("{:.*e}", precision.unwrap_or(6), value), | ||
| 'E' => format!("{:.*E}", precision.unwrap_or(6), value), |
There was a problem hiding this comment.
Scientific notation exponent format differs from C standard
Low Severity
Rust's scientific notation format differs from C's %e/%E output. Rust produces exponents like "1.23e4" (no sign for positive, minimal digits), while C produces "1.23e+04" (explicit + sign, at least two digits). This affects all %e, %E, %g, and %G format specifiers and could cause compatibility issues with downstream tools or MATLAB workflows that expect C-style exponent formatting. The exponent_part is used directly from Rust's format output without normalization to C conventions.
Additional Locations (1)
…g bugs - Parse and preserve all printf format flags (+, -, space, 0, #) and width specifiers - Fix Bug 1: # flag no longer appends decimal point to special float values (inf, nan) - Fix Bug 2: # flag correctly inserts decimal point before exponent in exponential notation - Add comprehensive tests for hash flag behavior with special values and exponents - Restore full C-style printf format compatibility for Windows snprintf fallback
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| formatted.push('.'); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Hash flag for %g format doesn't preserve trailing zeros
Medium Severity
The # flag for %g/%G format specifiers only adds a decimal point but doesn't preserve trailing zeros. In C's printf, %#g requires trailing zeros to NOT be removed from the fractional part. The current implementation unconditionally calls trim_trailing_decimal in format_general before the hash flag is checked in format_with_spec, so format strings like %#.5g with value 1.0 produce "1." instead of the expected "1.0000".
Problem
Note
Replaces C
_snprintf/snprintfon Windows with a Rustplatform_snprintfthat parses and formats%e/%E/%f/%F/%g/%Gwith flags, width, and precision, including#, sign, zero-padding, alignment, and proper handling ofNaN/Inf.#[cfg(windows)]and keeps libcsnprintffor non-Windowsc_intimport and adjusts return sizing to match C semantics#flag behavior for special values and decimal insertion before exponentWritten by Cursor Bugbot for commit 64c2344. This will update automatically on new commits. Configure here.