aboutsummaryrefslogtreecommitdiff
path: root/lib/std/fmt.zig
AgeCommit message (Collapse)Author
2022-08-22stage2+stage1: remove type parameter from bit builtinsVeikka Tuominen
Closes #12529 Closes #12511 Closes #6835
2022-07-27std.fmt: add more invalid format string errorsr00ster91
2022-07-27std.fmt: lowercase compile errorsr00ster91
`compileError\("([A-Z])` and `compileError\("\L\1`. It's pretty convenient.
2022-07-26std.fmt: require specifier for unwrapping ?T and E!TInKryption
2022-07-24Revert "std.fmt: require specifier for unwrapping ?T and E!T."Andrew Kelley
This reverts commit 7cbd586ace46a8e8cebab660ebca3cfc049305d9. This is causing a fail to build from source: ``` ./lib/std/fmt.zig:492:17: error: cannot format optional without a specifier (i.e. {?} or {any}) @compileError("cannot format optional without a specifier (i.e. {?} or {any})"); ^ ./src/link/MachO/Atom.zig:544:26: note: called from here log.debug(" RELA({s}) @ {x} => %{d} in object({d})", .{ ^ ``` I looked at the code to fix it but none of those args are optionals.
2022-07-24std.fmt: require specifier for unwrapping ?T and E!T.InKryption
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-07-21Fix #9184: fmtIntSizeDec/fmtIntSizeBin support FormatOptionsYujiri
2022-07-11std.fmt: clarify the description of placeholders in Format StringsDuncan Holm
Those 6 sets of square brackets are just a typographical aid used in this doc-comment, and must not actually be written by the user in their own format string... except for in one case where they must * Avoid the implication that the numeric index is 1-based rather than 0-based
2022-07-10compiler_rt: Update Windows ABI for float<->int conversion routinesCody Tapscott
Starting with LLVM 14, the Libcalls to these functions are now lowered using a Vec(2, u64) instead of the standard ABI for i128 integers, so our compiler-rt implementation needs to be updated to expose the same ABI on Windows.
2022-07-09two more regressed test cases; same cause as last two commitsAndrew Kelley
2022-07-09disable regressed float formatting test caseAndrew Kelley
See #12063
2022-07-05Merge remote-tracking branch 'origin/master' into llvm14Andrew Kelley
2022-07-05std: align some function pointersAndrew Kelley
2022-07-03std: disable tests regressed from LLVM 14Andrew Kelley
2022-06-30stage2: lower float negation explicitlyAndrew Kelley
Rather than lowering float negation as `0.0 - x`. * Add AIR instruction for float negation. * Add compiler-rt functions for f128, f80 negation closes #11853
2022-06-20std.fmt: update test to stage2 fn pointer semanticsVeikka Tuominen
2022-06-12std: disable failing tests, add zig2 build test-std to CIVeikka Tuominen
2022-06-11stage2: improve anon name strategy for local variablesVeikka Tuominen
2022-06-11Sema: handle tuple and anon_struct in resolveTypeFullyVeikka Tuominen
2022-06-03std: update tests to stage2 semanticsVeikka Tuominen
2022-06-03std: disable tests that crash stage2Veikka Tuominen
2022-05-27math: make `cast` return optional instead of an errorAli Chraghi
2022-05-23document bufPrint, and format now uses `writer` not `output`Dominic Tarr
2022-05-03temporary fix for stage2/stage1 f128 rounding discrepencyMarc Tiehuis
This is only to get tests running again. The root issue should be fixed in stage1 so rounding is consistent between stages.
2022-05-03add new float-parser based on eisel-lemire algorithmMarc Tiehuis
The previous float-parsing method was lacking in a lot of areas. This commit introduces a state-of-the art implementation that is both accurate and fast to std. Code is derived from working repo https://github.com/tiehuis/zig-parsefloat. This includes more test-cases and performance numbers that are present in this commit. * Accuracy The primary testing regime has been using test-data found at https://github.com/tiehuis/parse-number-fxx-test-data. This is a fork of upstream with support for f128 test-cases added. This data has been verified against other independent implementations and represents accurate round-to-even IEEE-754 floating point semantics. * Performance Compared to the existing parseFloat implementation there is ~5-10x performance improvement using the above corpus. (f128 parsing excluded in below measurements). ** Old $ time ./test_all_fxx_data 3520298/5296694 succeeded (1776396 fail) ________________________________________________________ Executed in 28.68 secs fish external usr time 28.48 secs 0.00 micros 28.48 secs sys time 0.08 secs 694.00 micros 0.08 secs ** This Implementation $ time ./test_all_fxx_data 5296693/5296694 succeeded (1 fail) ________________________________________________________ Executed in 4.54 secs fish external usr time 4.37 secs 515.00 micros 4.37 secs sys time 0.10 secs 171.00 micros 0.10 secs Further performance numbers can be seen using the https://github.com/tiehuis/simple_fastfloat_benchmark/ repository, which compares against some other well-known string-to-float conversion functions. A breakdown can be found here: https://github.com/tiehuis/zig-parsefloat/blob/0d9f020f1a37ca88bf889703b397c1c41779f090/PERFORMANCE.md#commit-b15406a0d2e18b50a4b62fceb5a6a3bb60ca5706 In summary, we are within 20% of the C++ reference implementation and have about ~600-700MB/s throughput on a Intel I5-6500 3.5Ghz. * F128 Support Finally, f128 is now completely supported with full accuracy. This does use a slower path which is possible to improve in future. * Behavioural Changes There are a few behavioural changes to note. - `parseHexFloat` is now redundant and these are now supported directly in `parseFloat`. - We implement round-to-even in all parsing routines. This is as specified by IEEE-754. Previous code used different rounding mechanisms (standard was round-to-zero, hex-parsing looked to use round-up) so there may be subtle differences. Closes #2207. Fixes #11169.
2022-04-27std: replace usage of std.meta.bitCount() with @bitSizeOf()Isaac Freund
2022-04-25stdlib: Fix hex-float printing for f80Cody Tapscott
2022-04-15Add `std.unicode.replacement_character`r00ster91
2022-04-14stage2: progress towards stage3Andrew Kelley
* The `@bitCast` workaround is removed in favor of `@ptrCast` properly doing element casting for slice element types. This required an enhancement both to stage1 and stage2. * stage1 incorrectly accepts `.{}` instead of `{}`. stage2 code that abused this is fixed. * Make some parameters comptime to support functions in switch expressions (as opposed to making them function pointers). * Avoid relying on local temporaries being mutable. * Workarounds for when stage1 and stage2 disagree on function pointer types. * Workaround recursive formatting bug with a `@panic("TODO")`. * Remove unreachable `else` prongs for some inferred error sets. All in effort towards #89.
2022-04-07use math/float.zig everywhereviri
2022-04-04std.fmt: Fix incorrect behavior with large floating point integers.Evan Haas
I consider this an interim workaround/hack until #1299 is finished. There is a bug in the original C implementation of the errol3 (and errol4) algorithm that can result in undefined behavior or an obviously incorrect result (leading ':' in the output) This change checks for those two problems and uses a slower fallback path if they occur. I can't guarantee that this will always produce the correct result, but since the workaround is only used if the original algorithm is guaranteed to fail, it should never turn a previously-correct result into an incorrect one. Fixes #11283
2022-03-30replace other uses of `std.meta.Vector` with `@Vector` (#11346)Meghan
2022-03-21stage2 llvm: fix lowerDeclRefValue for function aliasesVeikka Tuominen
2022-03-19stage1: make type names more uniqueRobin Voetter
2022-02-19AstGen: evaluate `comptime var` init expressions in a comptime contextAndrew Kelley
2022-02-16fmt: allow uppercase prefix to be parsed in std.fmt.parseInt()iddev5
std.fmt.parseHexFloat allow both 0x and 0X as prefix, so in order to keep things consistent. This commit modifies std.fmt.parseWithSign to check for the prefix case insensitively in order to allow both upper case and lower case prefix. This change now allows: 0O, 0B and 0X as prefixes for parsing.
2022-01-29std.fmt: fix out-of-bounds array write in float printingJohn Schmidt
This commit fixes an out of bounds write that can occur when formatting certain float values. The write messes up the stack and causes incorrect results, segfaults, or nothing at all, depending on the optimization mode used. The `errol` function writes the digits of the float into `buffer` starting from index 1, leaving index 0 untouched, and returns `buffer[1..]` and the exponent. This is because `roundToPrecision` relies on index 0 being unused in case the rounding adds a digit (e.g rounding 999.99 to 1000.00). When this happens, pointer arithmetic is used [here](https://github.com/ziglang/zig/blob/0e6d2184cacf2dd1fad7508b2f9ae99d78763148/lib/std/fmt/errol.zig#L61-L65) to access index 0 and put the ones digit in the right place. However, `errol3u` contains two special cases: `errolInt` and `errolFixed`, which return from the function early. For these two special cases index 0 was never reserved, and the return value contains `buffer` instead of `buffer[1..]`. This causes the pointer arithmetic in `roundToPrecision` to write out of bounds, which in the case of `std.fmt.formatFloatDecimal` messes up the stack and causes undefined behavior. The fix is to move the slicing of `buffer` to `buffer[1..]` from `errol3u` to `errol` so that both the default and the special cases operate on the sliced buffer.
2022-01-24Handle FormatOptions in fmtDuration/fmtDurationSignedJohn Schmidt
2022-01-01fmt: Refactor parsing of placeholders into its own functionJimmi Holst Christensen
This saves on comptime format string parsing, as the compiler caches comptime calls. The catch here, is that parsePlaceHolder cannot take the placeholder string as a slice. It must take it as an array by value for the caching to occure. There is also some logic in here that ensures that the specifier_arg is always them same slice when the items they contain are the same. This makes the compiler stamp out less copies of formatType.
2022-01-01std.fmt: improve `@compileError` messager00ster
2021-12-29Fixed typo in deprecation error for `E` format specifier where it would ↵Tom Manner
instead complain about a specifier of `X`.
2021-11-30allocgate: std Allocator interface refactorLee Cannon
2021-11-30std lib API deprecations for the upcoming 0.9.0 releaseAndrew Kelley
See #3811
2021-10-17std: Fix endless loop in fmt implLemonBoy
Apparently there's a stage1 bug that may sometimes lead to an endless loop being generated when unrolling the fmt impl. Closes #9961
2021-09-15Merge remote-tracking branch 'origin/master' into llvm13Andrew Kelley
Conflicts: * cmake/Findclang.cmake * cmake/Findlld.cmake * cmake/Findllvm.cmake In master branch, more search paths were added to these files with "12" in the path. In this commit I updated them to "13". * src/stage1/codegen.cpp * src/zig_llvm.cpp * src/zig_llvm.h In master branch, ZigLLVMBuildCmpXchg is improved to add `is_single_threaded`. However, the LLVM 13 C API has this already, and in the llvm13 branch, ZigLLVMBuildCmpXchg is deleted in favor of the C API. In this commit I updated stage2 to use the LLVM 13 C API rather than depending on an improved ZigLLVMBuildCmpXchg. Additionally, src/target.zig largestAtomicBits needed to be updated to include the new m68k ISA.
2021-09-01std: reorganization that allows new usingnamespace semanticsAndrew Kelley
The proposal #9629 is now accepted, usingnamespace stays but no longer puts identifiers in scope.
2021-09-01re-enable mips behavior tests for vectorsAndrew Kelley
closes #3317
2021-08-30Fix float formatting for 0.0 when precision is 0 (#9642)Boo
2021-08-24remove redundant license headers from zig standard libraryAndrew Kelley
We already have a LICENSE file that covers the Zig Standard Library. We no longer need to remind everyone that the license is MIT in every single file. Previously this was introduced to clarify the situation for a fork of Zig that made Zig's LICENSE file harder to find, and replaced it with their own license that required annual payments to their company. However that fork now appears to be dead. So there is no need to reinforce the copyright notice in every single file.
2021-08-20std.json: Add support for recursive objects to std.json.parse (#9307)Dmitry Matveyev
* Add support for recursive objects to std.json.parse * Remove previously defined error set * Try with function which returns an error set * Don't analyze already inferred types * Add comptime to inferred_type parameter * Make ParseInternalError to accept only a single argument * Add public `ParseError` for `parse` function * Use error.Foo syntax for errors instead of a named error set * Better formatting * Update to latest code changes