Skip to content

Commit f44ec20

Browse files
authored
Fix #122 via from ckormanyos/issue_0122
Fixes #122
2 parents c390206 + 905686a commit f44ec20

16 files changed

+126
-181
lines changed

.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Checks: >
1212
1313
WarningsAsErrors: '*'
1414
HeaderFilterRegex: '.*'
15-
AnalyzeTemporaryDtors: false
1615
FormatStyle: none
1716
User: john
1817
CheckOptions:

.github/workflows/soft_double.yml

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -294,30 +294,46 @@ jobs:
294294
fetch-depth: '0'
295295
- name: update-tools
296296
run: |
297-
sudo apt install libncurses5 libpython2.7
297+
sudo apt update
298+
wget http://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb
299+
sudo apt install ./libtinfo5_6.3-2ubuntu0.1_amd64.deb
300+
wget http://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/libncursesw5_6.3-2ubuntu0.1_amd64.deb
301+
sudo apt install ./libncursesw5_6.3-2ubuntu0.1_amd64.deb
298302
mkdir -p emu_env && cd emu_env
299-
wget --no-check-certificate https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2
300-
tar -xvf gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2
301-
wget --no-check-certificate https://github.com/xpack-dev-tools/qemu-arm-xpack/releases/download/v7.1.0-1/xpack-qemu-arm-7.1.0-1-linux-x64.tar.gz
302-
tar -xvzf xpack-qemu-arm-7.1.0-1-linux-x64.tar.gz
303+
wget --no-check-certificate https://developer.arm.com/-/media/Files/downloads/gnu/13.3.rel1/binrel/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi.tar.xz
304+
tar -xf arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi.tar.xz
305+
wget --no-check-certificate https://github.com/xpack-dev-tools/qemu-arm-xpack/releases/download/v8.2.6-1/xpack-qemu-arm-8.2.6-1-linux-x64.tar.gz
306+
tar -xzf xpack-qemu-arm-8.2.6-1-linux-x64.tar.gz
303307
working-directory: ./
304308
- name: build-example-stm32f429
305309
run: |
310+
PATH="${{ runner.workspace }}/soft_double/emu_env/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi/bin:$PATH"
311+
echo 'Query arm-none-eabi-g++ version'
312+
echo
313+
arm-none-eabi-g++ -v
314+
echo
306315
mkdir -p bin
307-
emu_env/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-g++ -std=${{ matrix.standard }} -Werror -Wall -Wextra -Wpedantic -pedantic -O0 -g -gdwarf-2 -ffunction-sections -fdata-sections -x c++ -fno-rtti -fno-use-cxa-atexit -fno-exceptions -fno-nonansi-builtins -fno-threadsafe-statics -fno-enforce-eh-specs -ftemplate-depth=32 -mcpu=cortex-m4 -mtune=cortex-m4 -mthumb -mfloat-abi=soft -mno-unaligned-access -mno-long-calls -I. -DWIDE_INTEGER_STANDALONE_EXAMPLE010_HYPERGEOMETRIC_2F1 examples/example010_hypergeometric_2f1.cpp ./target/micros/stm32f429/make/single/crt.cpp -nostartfiles -Wl,--gc-sections -Wl,-Map,./bin/example010_hypergeometric_2f1.map -T ./target/micros/stm32f429/make/stm32f429.ld --specs=nano.specs --specs=nosys.specs -o ./bin/example010_hypergeometric_2f1.elf
308-
emu_env/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-objcopy ./bin/example010_hypergeometric_2f1.elf -O ihex ./bin/example010_hypergeometric_2f1.hex
316+
arm-none-eabi-g++ -std=${{ matrix.standard }} -Werror -Wall -Wextra -Wpedantic -pedantic -O0 -g -gdwarf-2 -ffunction-sections -fdata-sections -x c++ -fno-rtti -fno-use-cxa-atexit -fno-exceptions -fno-nonansi-builtins -fno-threadsafe-statics -fno-enforce-eh-specs -ftemplate-depth=32 -mcpu=cortex-m4 -mtune=cortex-m4 -mthumb -mfloat-abi=soft -mno-unaligned-access -mno-long-calls -I. -DWIDE_INTEGER_STANDALONE_EXAMPLE010_HYPERGEOMETRIC_2F1 examples/example010_hypergeometric_2f1.cpp ./target/micros/stm32f429/make/single/crt.cpp -nostartfiles -Wl,--gc-sections -Wl,-Map,./bin/example010_hypergeometric_2f1.map -T ./target/micros/stm32f429/make/stm32f429.ld --specs=nano.specs --specs=nosys.specs -o ./bin/example010_hypergeometric_2f1.elf
317+
arm-none-eabi-objcopy ./bin/example010_hypergeometric_2f1.elf -O ihex ./bin/example010_hypergeometric_2f1.hex
309318
ls -la ./bin/example010_hypergeometric_2f1.elf ./bin/example010_hypergeometric_2f1.hex ./bin/example010_hypergeometric_2f1.map
310319
working-directory: ./
311320
- name: emulate-target stm32f429
312321
run: |
313-
./emu_env/xpack-qemu-arm-7.1.0-1/bin/qemu-system-gnuarmeclipse --verbose --mcu STM32F429ZI --nographic --gdb tcp::9999 -d unimp,guest_errors &
322+
PATH="${{ runner.workspace }}/soft_double/emu_env/xpack-qemu-arm-8.2.6-1/bin:$PATH"
323+
qemu-system-gnuarmeclipse --verbose --mcu STM32F429ZI --nographic --gdb tcp::9999 -d unimp,guest_errors &
324+
sleep 2
314325
working-directory: ./
315326
- name: run-test-on-target
316327
run: |
317-
./emu_env/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gdb-py ./bin/example010_hypergeometric_2f1.elf -x ./target/build/test_examples_emulator.py
318-
qemu_result=$?
319-
echo "qemu_result" "$qemu_result"
320-
echo "qemu_result" "$qemu_result" | grep 'qemu_result 0'
328+
sleep 2
329+
PATH="${{ runner.workspace }}/soft_double/emu_env/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi/bin:$PATH"
330+
echo 'Run test on target'
331+
echo
332+
arm-none-eabi-gdb ./bin/example010_hypergeometric_2f1.elf -x ./target/build/test_examples_emulator.gdb > ./example010_hypergeometric_2f1.txt
333+
cat ./example010_hypergeometric_2f1.txt
334+
echo
335+
echo 'We will now grep for the right answer...'
336+
grep 'value 0xF00DCAFE' ./example010_hypergeometric_2f1.txt
321337
working-directory: ./
322338
gcc-clang-boost-math-snippets:
323339
runs-on: ubuntu-latest

.tidy/make/make_tidy_03_flags.gmk

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ------------------------------------------------------------------------------
2-
# Copyright Christopher Kormanyos 2022 - 2023.
2+
# Copyright Christopher Kormanyos 2022 - 2025.
33
# Distributed under the Boost Software License,
44
# Version 1.0. (See accompanying file LICENSE_1_0.txt
55
# or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -35,12 +35,25 @@ C_INCLUDES :=$(addprefix -I,$(C_INCLUDES))
3535

3636

3737
TIDY_CHECKS = "*, \
38-
-altera-struct-pack-align, \
39-
-altera-unroll-loops, \
40-
-fuchsia-*, \
41-
-llvmlibc-*, \
42-
-readability-identifier-length, \
43-
-readability-identifier-naming"
38+
-cert-dcl58-cpp, \
39+
-cppcoreguidelines-rvalue-reference-param-not-moved, \
40+
-cppcoreguidelines-avoid-do-while, \
41+
-modernize-type-traits, \
42+
-modernize-use-constraints, \
43+
-misc-header-include-cycle, \
44+
-misc-include-cleaner, \
45+
-misc-const-correctness, \
46+
-modernize-use-std-numbers, \
47+
-performance-avoid-endl, \
48+
-readability-avoid-nested-conditional-operator, \
49+
-readability-identifier-length, \
50+
-readability-identifier-naming, \
51+
-readability-redundant-casting, \
52+
-altera-struct-pack-align, \
53+
-altera-unroll-loops, \
54+
-fuchsia-*, \
55+
-llvmlibc-*"
56+
4457

4558
TIDY_FLAGS = --extra-arg-before=--driver-mode=g++ \
4659
-warnings-as-errors=* \

examples/example001_roots_sqrt.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
///////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2020 - 2022. //
2+
// Copyright Christopher Kormanyos 2020 - 2025. //
33
// Distributed under the Boost Software License, //
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt //
55
// or copy at http://www.boost.org/LICENSE_1_0.txt) //
66
///////////////////////////////////////////////////////////////////
77

88
#include <cmath>
9-
#include <cstdint>
109

1110
#include <math/softfloat/soft_double.h>
1211
#include <math/softfloat/soft_double_examples.h>
@@ -48,7 +47,7 @@ auto math::softfloat::example001_roots_sqrt() -> bool
4847
}
4948

5049
// Enable this if you would like to activate this main() as a standalone example.
51-
#if 0
50+
#if 0 // NOLINT(readability-avoid-unconditional-preprocessor-if)
5251

5352
#include <iomanip>
5453
#include <iostream>

examples/example004_bessel_recur.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ auto bisect(const std::function<FloatingPointType(const FloatingPointType)>& pfn
3636
{
3737
// Bisection interval has no root or it has multiple roots!
3838

39-
return static_cast<floating_point_type>(static_cast<int>(INT8_C(0)));
39+
return static_cast<floating_point_type>(static_cast<int>(INT8_C(0))); // NOLINT(readability-redundant-casting)
4040
}
4141

4242
// Orient the search such that f > 0 lies at x + dx.
@@ -248,7 +248,7 @@ auto math::softfloat::example004_bessel_recur() -> bool
248248
}
249249

250250
// Enable this if you would like to activate this main() as a standalone example.
251-
#if 0
251+
#if 0 // NOLINT(readability-avoid-unconditional-preprocessor-if)
252252

253253
#include <iomanip>
254254
#include <iostream>

examples/example005_polylog_series.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ auto math::softfloat::example005_polylog_series() -> bool
101101
}
102102

103103
// Enable this if you would like to activate this main() as a standalone example.
104-
#if 0
104+
#if 0 // NOLINT(readability-avoid-unconditional-preprocessor-if)
105105

106106
#include <iomanip>
107107
#include <iostream>

examples/example007_catalan_series.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ auto math::softfloat::example007_catalan_series() -> bool
142142
}
143143

144144
// Enable this if you would like to activate this main() as a standalone example.
145-
#if 0
145+
#if 0 // NOLINT(readability-avoid-unconditional-preprocessor-if)
146146

147147
#include <iomanip>
148148
#include <iostream>

examples/example011_trig_trapezoid_integral.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ auto math::softfloat::example011_trig_trapezoid_integral() -> bool
159159
}
160160

161161
// Enable this if you would like to activate this main() as a standalone example.
162-
#if 0
162+
#if 0 // NOLINT(readability-avoid-unconditional-preprocessor-if)
163163

164164
#include <iomanip>
165165
#include <iostream>

examples/example012_exercise_constexpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ auto math::softfloat::example012_exercise_constexpr() -> bool
5151

5252

5353
// Enable this if you would like to activate this main() as a standalone example.
54-
#if 0
54+
#if 0 // NOLINT(readability-avoid-unconditional-preprocessor-if)
5555

5656
#include <iomanip>
5757
#include <iostream>

math/softfloat/soft_double.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
///////////////////////////////////////////////////////////////////
2-
// Copyright Christopher Kormanyos 2012 - 2024. //
2+
// Copyright Christopher Kormanyos 2012 - 2025. //
33
// Distributed under the Boost Software License, //
44
// Version 1.0. (See accompanying file LICENSE_1_0.txt //
55
// or copy at http://www.boost.org/LICENSE_1_0.txt) //
@@ -421,7 +421,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
421421
using float_type = BuiltInFloatType;
422422
using unsigned_type = ExactUnsignedIntegralType;
423423

424-
const float_type my_f; // NOLINT(misc-non-private-member-variables-in-classes)
424+
const float_type my_f; // NOLINT(misc-non-private-member-variables-in-classes,cppcoreguidelines-avoid-const-or-ref-data-members)
425425

426426
explicit constexpr uz_type(float_type f) noexcept : my_f(f) { }
427427

@@ -733,7 +733,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
733733
SOFT_DOUBLE_NODISCARD constexpr auto to_float() const -> typename std::enable_if<( (sizeof(FloatingPointType) == static_cast<std::size_t>(UINT8_C(8)))
734734
&& std::numeric_limits<FloatingPointType>::is_iec559), FloatingPointType>::type
735735
{
736-
return static_cast<FloatingPointType>(*static_cast<const volatile FloatingPointType*>(static_cast<const volatile void*>(this)));
736+
return static_cast<FloatingPointType>(*static_cast<const volatile FloatingPointType*>(static_cast<const volatile void*>(this))); // NOLINT(bugprone-casting-through-void)
737737
}
738738

739739
public:
@@ -1371,19 +1371,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13711371
static constexpr auto f64_to_f32(const std::uint64_t a) -> float
13721372
{
13731373
return
1374-
softfloat_roundPackToF32
1375-
(
1376-
detail::signF64UI(a),
1377-
static_cast<std::int16_t>(detail::expF64UI(a) - static_cast<std::int16_t>(INT16_C(0x381))),
1378-
static_cast<std::uint32_t>
1379-
(
1374+
(a == 0)
1375+
? 0.0F // See issue 122 at: https://github.com/ckormanyos/soft_double/issues/122
1376+
: softfloat_roundPackToF32
1377+
(
1378+
detail::signF64UI(a),
1379+
static_cast<std::int16_t>(detail::expF64UI(a) - static_cast<std::int16_t>(INT16_C(0x381))),
13801380
static_cast<std::uint32_t>
13811381
(
1382-
detail::softfloat_shortShiftRightJam64(detail::fracF64UI(a), static_cast<std::uint_fast16_t>(UINT8_C(22)))
1382+
static_cast<std::uint32_t>
1383+
(
1384+
detail::softfloat_shortShiftRightJam64(detail::fracF64UI(a), static_cast<std::uint_fast16_t>(UINT8_C(22)))
1385+
)
1386+
| static_cast<std::uint32_t>(UINT32_C(0x40000000))
13831387
)
1384-
| static_cast<std::uint32_t>(UINT32_C(0x40000000))
1385-
)
1386-
);
1388+
);
13871389
}
13881390

13891391
static constexpr auto softfloat_roundPackToF32(bool sign, std::int16_t expA, std::uint32_t sig) -> float

0 commit comments

Comments
 (0)