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

Formatted output for real #272

Merged
merged 20 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 12 additions & 38 deletions .circleci/config.yml
@@ -1,4 +1,4 @@
version: 2
version: 2.1

jobs:
bionic_gcc7_conda_coverage:
Expand Down Expand Up @@ -33,14 +33,6 @@ jobs:
- run:
name: Build and test
command: bash ./tools/circleci_focal_gcc9_conda_docs.sh
focal_clang9_conda_tsan:
docker:
- image: circleci/buildpack-deps:focal
steps:
- checkout
- run:
name: Build and test
command: bash ./tools/circleci_focal_clang9_conda_tsan.sh
focal_clang9_debuggmp_unstable:
docker:
- image: circleci/buildpack-deps:focal
Expand All @@ -57,30 +49,6 @@ jobs:
- run:
name: Build and test
command: bash ./tools/circleci_focal_clang9_debuggmp.sh
bionic_gcc7_conda_asan:
docker:
- image: circleci/buildpack-deps:bionic
steps:
- checkout
- run:
name: Build and test
command: bash ./tools/circleci_bionic_gcc7_conda_asan.sh
bionic_gcc7_conda_ubsan:
docker:
- image: circleci/buildpack-deps:bionic
steps:
- checkout
- run:
name: Build and test
command: bash ./tools/circleci_bionic_gcc7_conda_ubsan.sh
bionic_clang6:
docker:
- image: circleci/buildpack-deps:bionic
steps:
- checkout
- run:
name: Build and test
command: bash ./tools/circleci_bionic_clang6.sh
focal_clang9_msan_00:
docker:
- image: circleci/buildpack-deps:focal
Expand All @@ -103,20 +71,26 @@ jobs:
environment:
TEST_NSPLIT: 2
SPLIT_TEST_NUM: 1
ubuntu_arm64:
machine:
image: ubuntu-2004:202101-01
resource_class: arm.medium
steps:
- checkout
- run:
name: Build and test
command: bash ./tools/circleci_ubuntu_arm64.sh

workflows:
version: 2
version: 2.1
all_builds:
jobs:
- focal_clang9_msan_00
- focal_clang9_msan_01
- bionic_clang6
- bionic_gcc7_conda_coverage
- bionic_gcc7_conda_release
- focal_gcc9_conda_coverage
- focal_clang9_conda_tsan
- focal_clang9_debuggmp_unstable
- focal_clang9_debuggmp
- bionic_gcc7_conda_asan
- bionic_gcc7_conda_ubsan
- focal_gcc9_conda_docs
- ubuntu_arm64
2 changes: 1 addition & 1 deletion .clang-tidy
@@ -1,5 +1,5 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,*,-hicpp-uppercase-literal-suffix,-readability-uppercase-literal-suffix,-modernize-use-trailing-return-type,-readability-named-parameter,-hicpp-named-parameter,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-hicpp-no-array-decay,-llvm-header-guard,-cppcoreguidelines-macro-usage,-google-runtime-references,-readability-isolate-declaration,-fuchsia-default-arguments-calls,-fuchsia-overloaded-operator,-fuchsia-default-arguments-declarations,-readability-else-after-return,-google-runtime-int,-hicpp-signed-bitwise,-cert-dcl21-cpp,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-avoid-c-arrays,-hicpp-avoid-c-arrays,-modernize-avoid-c-arrays,-modernize-use-transparent-functors,-cert-dcl16-c,-cppcoreguidelines-pro-type-union-access,-bugprone-branch-clone,-fuchsia-statically-constructed-objects,-cppcoreguidelines-pro-bounds-constant-array-index,-readability-static-accessed-through-instance,-cppcoreguidelines-pro-type-vararg,-hicpp-vararg,-llvmlibc-restrict-system-libc-headers,-llvmlibc-callee-namespace,-llvmlibc-implementation-in-namespace,-llvm-else-after-return'
Checks: 'clang-diagnostic-*,clang-analyzer-*,*,-hicpp-uppercase-literal-suffix,-readability-uppercase-literal-suffix,-modernize-use-trailing-return-type,-readability-named-parameter,-hicpp-named-parameter,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-hicpp-no-array-decay,-llvm-header-guard,-cppcoreguidelines-macro-usage,-google-runtime-references,-readability-isolate-declaration,-fuchsia-default-arguments-calls,-fuchsia-overloaded-operator,-fuchsia-default-arguments-declarations,-readability-else-after-return,-google-runtime-int,-hicpp-signed-bitwise,-cert-dcl21-cpp,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-avoid-c-arrays,-hicpp-avoid-c-arrays,-modernize-avoid-c-arrays,-modernize-use-transparent-functors,-cert-dcl16-c,-cppcoreguidelines-pro-type-union-access,-bugprone-branch-clone,-fuchsia-statically-constructed-objects,-cppcoreguidelines-pro-bounds-constant-array-index,-readability-static-accessed-through-instance,-cppcoreguidelines-pro-type-vararg,-hicpp-vararg,-llvmlibc-restrict-system-libc-headers,-llvmlibc-callee-namespace,-llvmlibc-implementation-in-namespace,-llvm-else-after-return,-altera-struct-pack-align,-readability-function-cognitive-complexity'
WarningsAsErrors: '*'
AnalyzeTemporaryDtors: false
FormatStyle: none
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/gh_actions_ci.yml
Expand Up @@ -7,6 +7,36 @@ on:
branches:
- master
jobs:
osx_10_15:
runs-on: macos-10.15
steps:
- uses: actions/checkout@v2
- name: Build
run: bash tools/gha_osx.sh
bionic_clang6:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Build
run: bash tools/gha_bionic_clang6.sh
bionic_gcc7_conda_asan:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Build
run: bash tools/gha_bionic_gcc7_conda_asan.sh
bionic_gcc7_conda_ubsan:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Build
run: bash tools/gha_bionic_gcc7_conda_ubsan.sh
focal_clang9_conda_tsan:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Build
run: bash tools/gha_focal_clang9_conda_tsan.sh
binder_cache:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
Expand Down
68 changes: 0 additions & 68 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
@@ -1,6 +1,6 @@
# mp++
[![Build Status](https://img.shields.io/circleci/project/github/bluescarni/mppp/master.svg?style=for-the-badge)](https://circleci.com/gh/bluescarni/mppp)
[![Build Status](https://img.shields.io/travis/bluescarni/mppp/master.svg?logo=travis&style=for-the-badge)](https://travis-ci.org/bluescarni/mppp)
[![Build Status](https://img.shields.io/github/workflow/status/bluescarni/mppp/GitHub%20CI?style=for-the-badge)](https://github.com/bluescarni/mppp/actions?query=workflow%3A%22GitHub+CI%22)
[![Build Status](https://img.shields.io/appveyor/ci/bluescarni/mppp/master.svg?logo=appveyor&style=for-the-badge)](https://ci.appveyor.com/project/bluescarni/mppp)
![language](https://img.shields.io/badge/language-C%2B%2B11-red.svg?style=for-the-badge)
[![Code Coverage](https://img.shields.io/codecov/c/github/bluescarni/mppp.svg?style=for-the-badge)](https://codecov.io/github/bluescarni/mppp?branch=master)
Expand Down
19 changes: 0 additions & 19 deletions azure-pipelines.yml

This file was deleted.

3 changes: 3 additions & 0 deletions doc/changelog.rst
Expand Up @@ -7,6 +7,9 @@ Changelog
New
~~~

- :cpp:class:`~mppp::real` now respects the format
flags in output streams
(`#272 <https://github.com/bluescarni/mppp/pull/272>`__).
- Add polylogarithms for :cpp:class:`~mppp::real`
(`#271 <https://github.com/bluescarni/mppp/pull/271>`__).
- Add the Lambert W functions :math:`W_0` and :math:`W_{-1}`
Expand Down
13 changes: 4 additions & 9 deletions doc/real.rst
Expand Up @@ -3059,21 +3059,16 @@ Input/Output

Output stream operator.

This operator will insert into the stream *os* a string representation of *r*
in base 10 (as returned by :cpp:func:`mppp::real::to_string()`).

.. warning::

In future versions of mp++, the behaviour of this operator will change to support the output stream's formatting
flags. For the time being, users are encouraged to use the ``mpfr_get_str()`` function from the MPFR
library if precise and forward-compatible control on the printing format is needed.
This function will direct to the output stream *os* the input :cpp:class:`~mppp::real` *r*.

:param os: the target stream.
:param r: the input argument.

:return: a reference to *os*.

:exception unspecified: any exception thrown by :cpp:func:`mppp::real::to_string()`.
:exception std\:\:overflow_error: in case of (unlikely) overflow errors.
:exception std\:\:invalid_argument: if the MPFR printing primitive ``mpfr_asprintf()`` returns an error code.
:exception unspecified: any exception raised by the public interface of ``std::ostream`` or by memory allocation errors.

.. _real_s11n:

Expand Down
13 changes: 8 additions & 5 deletions src/integer.cpp
Expand Up @@ -272,9 +272,6 @@ std::ostream &integer_stream_operator_impl(std::ostream &os, const mpz_struct_t
// Start by figuring out the base.
const auto base = stream_flags_to_base(flags);

// Determine the fill type.
const auto fill = stream_flags_to_fill(flags);

// Should we prefix the base? Do it only if:
// - the number is nonzero,
// - the showbase flag is set,
Expand Down Expand Up @@ -353,21 +350,26 @@ std::ostream &integer_stream_operator_impl(std::ostream &os, const mpz_struct_t
// only if the stream width is larger
// than the total size of the number.
if (width >= 0 && make_unsigned(width) > final_size) {
// Determine the fill type.
const auto fill = stream_flags_to_fill(flags);
// Compute how much fill we need.
const auto fill_size = safe_cast<decltype(tmp.size())>(make_unsigned(width) - final_size);
// Get the fill character.
const auto fill_char = os.fill();
// NOLINTNEXTLINE(hicpp-multiway-paths-covered)

switch (fill) {
case 1:
// Left fill: fill characters at the end.
// NOTE: minus 1 because of the terminator.
tmp.insert(tmp.end() - 1, fill_size, fill_char);
break;
case 2:
// Right fill: fill characters at the beginning.
tmp.insert(tmp.begin(), fill_size, fill_char);
break;
case 3: {
default: {
assert(fill == 3);

// Internal fill: the fill characters are always after the sign (if present)
// and the base prefix (if present).
auto delta = static_cast<int>(tmp[0] == '+' || tmp[0] == '-');
Expand All @@ -381,6 +383,7 @@ std::ostream &integer_stream_operator_impl(std::ostream &os, const mpz_struct_t
}

// Write out the unformatted data.
// NOTE: minus 1 because of the terminator.
os.write(tmp.data(), safe_cast<std::streamsize>(tmp.size() - 1u));

// Reset the stream width to zero, like the operator<<() does for builtin types.
Expand Down
12 changes: 7 additions & 5 deletions src/rational.cpp
Expand Up @@ -73,9 +73,6 @@ std::ostream &rational_stream_operator_impl(std::ostream &os, const mpz_struct_t
// Start by figuring out the base.
const auto base = stream_flags_to_base(flags);

// Determine the fill type.
const auto fill = stream_flags_to_fill(flags);

// Should we prefix the base? Do it only if:
// - the number is nonzero,
// - the showbase flag is set,
Expand Down Expand Up @@ -187,11 +184,14 @@ std::ostream &rational_stream_operator_impl(std::ostream &os, const mpz_struct_t
// only if the stream width is larger
// than the total size of the number.
if (width >= 0 && make_unsigned(width) > final_size) {
// Determine the fill type.
const auto fill = stream_flags_to_fill(flags);

// Compute how much fill we need.
const auto fill_size = safe_cast<decltype(tmp_num.size())>(make_unsigned(width) - final_size);
// Get the fill character.
const auto fill_char = os.fill();
// NOLINTNEXTLINE(hicpp-multiway-paths-covered)

switch (fill) {
case 1:
// Left fill: fill characters at the end.
Expand All @@ -208,7 +208,9 @@ std::ostream &rational_stream_operator_impl(std::ostream &os, const mpz_struct_t
// before the numerator starts).
tmp_num.insert(tmp_num.begin(), fill_size, fill_char);
break;
case 3: {
default: {
assert(fill == 3);

// Internal fill: the fill characters are always after the sign (if present).
// NOTE: contrary to integer, the internal fill does not take into account
// the base prefix, and it happens only if a sign is present.
Expand Down