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

Feature: serialize special numbers #884

Merged

Conversation

grisumbras
Copy link
Member

@grisumbras grisumbras commented May 7, 2023

  1. Change serializer to output special floating point numbers differently, so that the output is always valid JSON.
    • Infinity is output as 1e99999 (this number is so big that it is parsed by every implementation I am aware of as FP infinity).
    • NaN is output as null. It changes the type, and roundtrip won't happen, but at least it's not something that is not JSON.
  2. Add serializer option to enable an extension (the extension is incidentally the current behaviour)
    • Infinity is output as Infinity.
    • NaN is output as NaN.
  3. Add the ability to control serialisation options when outputting into ostreams.

The benefit for the second behaviour is that infinity and NaN are using unambiguous special representation.

Fix #350

@codecov
Copy link

codecov bot commented May 7, 2023

Codecov Report

Merging #884 (a4ecd74) into develop (ac9080c) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head a4ecd74 differs from pull request most recent head 6a12c32. Consider uploading reports for the commit 6a12c32 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #884   +/-   ##
========================================
  Coverage    99.24%   99.24%           
========================================
  Files           71       71           
  Lines         6861     6889   +28     
========================================
+ Hits          6809     6837   +28     
  Misses          52       52           
Impacted Files Coverage Δ
include/boost/json/serializer.hpp 100.00% <ø> (ø)
include/boost/json/detail/impl/format.ipp 100.00% <100.00%> (ø)
include/boost/json/detail/ryu/detail/common.hpp 100.00% <100.00%> (ø)
include/boost/json/detail/ryu/impl/d2s.ipp 99.55% <100.00%> (+<0.01%) ⬆️
include/boost/json/impl/serialize.ipp 95.60% <100.00%> (+0.66%) ⬆️
include/boost/json/impl/serializer.ipp 98.63% <100.00%> (+<0.01%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ac9080c...6a12c32. Read the comment docs.

@cppalliance-bot
Copy link

@grisumbras grisumbras force-pushed the feature/serialize-special-numbers branch from b0a1911 to 4300359 Compare May 8, 2023 08:23
@cppalliance-bot
Copy link

@grisumbras grisumbras force-pushed the feature/serialize-special-numbers branch from 4300359 to a4ecd74 Compare May 27, 2023 08:42
@grisumbras grisumbras force-pushed the feature/serialize-special-numbers branch from a4ecd74 to 6a12c32 Compare May 27, 2023 09:18
@grisumbras grisumbras merged commit 6a12c32 into boostorg:develop May 27, 2023
2 of 3 checks passed
@grisumbras grisumbras deleted the feature/serialize-special-numbers branch May 27, 2023 09:19
@cppalliance-bot
Copy link

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.

Fix the handling of NaN-s and infinities
2 participants