From c2ff10026dad4460aaabdd39181feae705103780 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 30 Aug 2025 19:01:11 -0500 Subject: [PATCH 01/14] cmake config --- .github/workflows/ci.yaml | 13 +++-- .gitignore | 2 + CMakeLists.txt | 82 +++++++++++++++++++++++++++++ compile_flags.txt | 30 ----------- makefile | 108 -------------------------------------- tests/CMakeLists.txt | 17 ++++++ tests/test_bmath.cc | 75 ++++++++++++++++++++++++++ tests/test_compilation.cc | 23 -------- 8 files changed, 186 insertions(+), 164 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 compile_flags.txt delete mode 100644 makefile create mode 100644 tests/CMakeLists.txt create mode 100644 tests/test_bmath.cc delete mode 100644 tests/test_compilation.cc diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 45f1de0..21cd678 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -22,9 +22,16 @@ jobs: build-and-test: runs-on: ubuntu-latest + strategy: + matrix: + build_type: [Debug, Release] steps: - uses: actions/checkout@v4 - name: Install compiler - run: sudo apt-get update && sudo apt-get install -y g++ - - name: Debug tests (asserts + sanitizers) - run: make test MODE=debug + run: sudo apt-get update && sudo apt-get install -y g++ cmake + - name: Configure CMake + run: cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + - name: Build + run: cmake --build build + - name: Test + run: ctest --test-dir build --output-on-failure diff --git a/.gitignore b/.gitignore index d3ad192..dd55ca5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ build/ +build-release/ +.cache/ *.o *.a *.swp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a06078c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,82 @@ +cmake_minimum_required(VERSION 3.20) +project( + bmath + VERSION 0.1.0 + DESCRIPTION "Header-only C++23 math library" + LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +add_library(bmath INTERFACE) +add_library(bmath::bmath ALIAS bmath) + +target_include_directories( + bmath INTERFACE $ + $) + +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL + "Clang") + target_compile_options( + bmath + INTERFACE -pedantic-errors + -Wall + -Wextra + -Wpedantic + -Wshadow + -Wformat=2 + -Wfloat-equal + -Wlogical-op + -Wshift-overflow=2 + -Wnon-virtual-dtor + -Wold-style-cast + -Wcast-qual + -Wuseless-cast + -Wno-sign-promotion + -Wcast-align + -Wunused + -Woverloaded-virtual + -Wconversion + -Wmisleading-indentation + -Wduplicated-cond + -Wduplicated-branches + -Wnull-dereference + -Wno-conversion + -Wformat-overflow + -Wformat-truncation + -Wdouble-promotion + -Wundef) +endif() + +target_compile_definitions(bmath INTERFACE LOCAL) + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + target_compile_options( + bmath + INTERFACE -O0 + -g3 + -fsanitize=address,undefined + -fsanitize=float-divide-by-zero + -fsanitize=float-cast-overflow + -fno-sanitize-recover=all + -fstack-protector-all + -fno-omit-frame-pointer + -fno-inline + -ffunction-sections) + + target_compile_definitions(bmath INTERFACE _GLIBCXX_DEBUG + _GLIBCXX_DEBUG_PEDANTIC) + + target_link_options( + bmath INTERFACE -fsanitize=address,undefined + -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow) +else() + target_compile_options(bmath INTERFACE -O2) + target_compile_definitions(bmath INTERFACE NDEBUG) +endif() + +enable_testing() +add_subdirectory(tests) diff --git a/compile_flags.txt b/compile_flags.txt deleted file mode 100644 index 541be64..0000000 --- a/compile_flags.txt +++ /dev/null @@ -1,30 +0,0 @@ --pedantic-errors --O2 --Wall --Wextra --Wpedantic --Wshadow --Wformat=2 --Wfloat-equal --Wlogical-op --Wshift-overflow=2 --Wnon-virtual-dtor --Wold-style-cast --Wcast-qual --Wuseless-cast --Wno-sign-promotion --Wcast-align --Wunused --Woverloaded-virtual --Wconversion --Wmisleading-indentation --Wduplicated-cond --Wduplicated-branches --Wlogical-op --Wnull-dereference --Wformat=2 --Wformat-overflow --Wformat-truncation --Wdouble-promotion --Wundef --DLOCAL diff --git a/makefile b/makefile deleted file mode 100644 index 3c4acfa..0000000 --- a/makefile +++ /dev/null @@ -1,108 +0,0 @@ -CXX ?= g++ - -INCLUDE_DIR := include -TEST_DIR := tests -BUILD_ROOT := build -MODE ?= release - -STD := -std=c++23 -WARNFLAGS := \ - -pedantic-errors \ - -Wall -Wextra -Wpedantic \ - -Wshadow \ - -Wformat=2 \ - -Wfloat-equal \ - -Wlogical-op \ - -Wshift-overflow=2 \ - -Wnon-virtual-dtor \ - -Wold-style-cast \ - -Wcast-qual \ - -Wuseless-cast \ - -Wno-sign-promotion \ - -Wcast-align \ - -Wunused \ - -Woverloaded-virtual \ - -Wconversion \ - -Wmisleading-indentation \ - -Wduplicated-cond \ - -Wduplicated-branches \ - -Wnull-dereference \ - -Wno-conversion \ - -Wformat-overflow \ - -Wformat-truncation \ - -Wdouble-promotion \ - -Wundef - -BASEDEFS := -DLOCAL -INCLUDES := -I$(INCLUDE_DIR) - -RELFLAGS := -O2 -DNDEBUG -DBGFLAGS := \ - -O0 -g3 \ - -fsanitize=address,undefined \ - -fsanitize=float-divide-by-zero \ - -fsanitize=float-cast-overflow \ - -fno-sanitize-recover=all \ - -fstack-protector-all \ - -fstack-usage \ - -fno-omit-frame-pointer \ - -fno-inline \ - -ffunction-sections \ - -D_GLIBCXX_DEBUG \ - -D_GLIBCXX_DEBUG_PEDANTIC - -DBG_LDFLAGS := \ - -fsanitize=address,undefined \ - -fsanitize=float-divide-by-zero \ - -fsanitize=float-cast-overflow - -CXXFLAGS := $(STD) $(WARNFLAGS) $(INCLUDES) $(BASEDEFS) -CXXFLAGS += -MMD -MP -ifeq ($(MODE),debug) - CXXFLAGS += $(DBGFLAGS) - LDFLAGS += $(DBG_LDFLAGS) -else - CXXFLAGS += $(RELFLAGS) -endif - -BUILD_DIR := $(BUILD_ROOT)/$(MODE) -TEST_SRC := $(wildcard $(TEST_DIR)/*.cc) -TEST_OBJ := $(patsubst $(TEST_DIR)/%.cc,$(BUILD_DIR)/$(TEST_DIR)/%.o,$(TEST_SRC)) -TEST_EXE := $(BUILD_DIR)/test_bmath - -.PHONY: all release debug test clean distclean flags .TEST - -all: release - -release: - $(MAKE) MODE=release .TEST - -debug: - $(MAKE) MODE=debug .TEST - -test: .TEST - -.TEST: $(TEST_EXE) - ./$(TEST_EXE) - -$(BUILD_DIR)/$(TEST_DIR)/%.o: $(TEST_DIR)/%.cc - @mkdir -p $(dir $@) - $(CXX) $(CXXFLAGS) -c $< -o $@ --include $(TEST_OBJ:.o=.d) - -$(TEST_EXE): $(TEST_OBJ) - @mkdir -p $(dir $@) - $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) - -flags: - @{ \ - printf "%s\n%s\n%s\n" $(STD) $(INCLUDES) $(WARNFLAGS) $(BASEDEFS) \ - [ "$(MODE)" = "debug" ] && printf "%s\n" $(DBGFLAGS) || printf "%s\n" $(RELFLAGS) \ - } > compile_flags.txt - -clean: - @rm -rf "$(BUILD_DIR)" - -distclean: - @rm -rf "$(BUILD_ROOT)" compile_flags.txt - diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..2fb3c98 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,17 @@ +include(FetchContent) +FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v1.14.0 +) +set(gtest_force_shared_crt + ON + CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) + +add_executable(test_bmath test_bmath.cc) + +target_link_libraries(test_bmath PRIVATE bmath::bmath gtest_main) + +include(GoogleTest) +gtest_discover_tests(test_bmath) diff --git a/tests/test_bmath.cc b/tests/test_bmath.cc new file mode 100644 index 0000000..2fd829c --- /dev/null +++ b/tests/test_bmath.cc @@ -0,0 +1,75 @@ +#include + +#include +#include + +#include "../include/bmath.hh" + +using namespace bmath; + +TEST(MintTest, BasicConstruction) { + mint four{4}; + + static_assert(std::is_trivially_copyable_v>); + + EXPECT_EQ(four.get(), 4); +} + +TEST(MintTest, Formatting) { + mint four{4}; + + auto formatted = std::format("{}", four); + EXPECT_EQ(formatted, "4"); + + auto string_result = to_string(four); + EXPECT_EQ(string_result, "4"); +} + +TEST(MintTest, Addition) { + mint a{3}; + mint b{5}; + + auto result = a + b; + EXPECT_EQ(result.get(), 8); +} + +TEST(MintTest, Subtraction) { + mint a{10}; + mint b{3}; + + auto result = a - b; + EXPECT_EQ(result.get(), 7); +} + +TEST(MintTest, Multiplication) { + mint a{6}; + mint b{7}; + + auto result = a * b; + EXPECT_EQ(result.get(), 42); +} + +TEST(MintTest, Modular) { + constexpr uint64_t mod = 13; + mint a{15}; + + EXPECT_EQ(a.get(), 2); +} + +TEST(PowerTest, BasicPower) { + mint base{2}; + auto result = pow(base, 3); + EXPECT_EQ(result.get(), 8); +} + +TEST(PowerTest, PowerOfOne) { + mint base{5}; + auto result = pow(base, 0); + EXPECT_EQ(result.get(), 1); +} + +TEST(PowerTest, PowerOfZero) { + mint base{0}; + auto result = pow(base, 5); + EXPECT_EQ(result.get(), 0); +} diff --git a/tests/test_compilation.cc b/tests/test_compilation.cc deleted file mode 100644 index e7112e7..0000000 --- a/tests/test_compilation.cc +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include - -#include "../include/bmath.hh" - -using namespace bmath; -using namespace std; - -int main() { - mint four{4}; - - // should be trivially copyable - static_assert(is_trivially_copyable_v>); - - // should be able to format - auto formatted = format("{}\n", four); - - // and use to_string - formatted = to_string(four); - - return 0; -} From 684051430a9b71cb178ebf2a4b9ef30e7033d8c2 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 30 Aug 2025 19:04:37 -0500 Subject: [PATCH 02/14] fix format --- .clang-format | 6 ------ CMakeLists.txt | 1 - 2 files changed, 7 deletions(-) diff --git a/.clang-format b/.clang-format index dc5ab4c..7be7fb6 100644 --- a/.clang-format +++ b/.clang-format @@ -15,7 +15,6 @@ AlignConsecutiveBitFields: AcrossEmptyLines: false AcrossComments: false AlignCompound: false - AlignFunctionDeclarations: false AlignFunctionPointers: false PadOperators: false AlignConsecutiveDeclarations: @@ -23,7 +22,6 @@ AlignConsecutiveDeclarations: AcrossEmptyLines: false AcrossComments: false AlignCompound: false - AlignFunctionDeclarations: true AlignFunctionPointers: false PadOperators: false AlignConsecutiveMacros: @@ -31,7 +29,6 @@ AlignConsecutiveMacros: AcrossEmptyLines: false AcrossComments: false AlignCompound: false - AlignFunctionDeclarations: false AlignFunctionPointers: false PadOperators: false AlignConsecutiveShortCaseStatements: @@ -45,7 +42,6 @@ AlignConsecutiveTableGenBreakingDAGArgColons: AcrossEmptyLines: false AcrossComments: false AlignCompound: false - AlignFunctionDeclarations: false AlignFunctionPointers: false PadOperators: false AlignConsecutiveTableGenCondOperatorColons: @@ -53,7 +49,6 @@ AlignConsecutiveTableGenCondOperatorColons: AcrossEmptyLines: false AcrossComments: false AlignCompound: false - AlignFunctionDeclarations: false AlignFunctionPointers: false PadOperators: false AlignConsecutiveTableGenDefinitionColons: @@ -61,7 +56,6 @@ AlignConsecutiveTableGenDefinitionColons: AcrossEmptyLines: false AcrossComments: false AlignCompound: false - AlignFunctionDeclarations: false AlignFunctionPointers: false PadOperators: false AlignEscapedNewlines: Left diff --git a/CMakeLists.txt b/CMakeLists.txt index a06078c..37d4c33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,6 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL -Wold-style-cast -Wcast-qual -Wuseless-cast - -Wno-sign-promotion -Wcast-align -Wunused -Woverloaded-virtual From c7893f598444c4b8e13b224c6707d19db4aec7d7 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 30 Aug 2025 19:04:55 -0500 Subject: [PATCH 03/14] fix(ci): only build release --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 21cd678..a134173 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,7 +24,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - build_type: [Debug, Release] + build_type: [Release] steps: - uses: actions/checkout@v4 - name: Install compiler From ba0fcd743244f65f4ab8a3872b1675f5246b8d97 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 30 Aug 2025 19:11:25 -0500 Subject: [PATCH 04/14] reorganize files and format --- include/bmath/bmath.hh | 6 ++++++ include/{bmath.hh => bmath/mint.hh} | 14 +++++++------- tests/test_bmath.cc | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 include/bmath/bmath.hh rename include/{bmath.hh => bmath/mint.hh} (95%) diff --git a/include/bmath/bmath.hh b/include/bmath/bmath.hh new file mode 100644 index 0000000..8c1b6d3 --- /dev/null +++ b/include/bmath/bmath.hh @@ -0,0 +1,6 @@ +#ifndef BMATH_BMATH_HH +#define BMATH_BMATH_HH + +#include "bmath/mint.hh" + +#endif diff --git a/include/bmath.hh b/include/bmath/mint.hh similarity index 95% rename from include/bmath.hh rename to include/bmath/mint.hh index 6e7881d..fc73e2c 100644 --- a/include/bmath.hh +++ b/include/bmath/mint.hh @@ -1,5 +1,7 @@ -#ifndef BMATH_HEADER_ONLY_MATH_LIB -#define BMATH_HEADER_ONLY_MATH_LIB +#ifndef BMATH_MINT_HH +#define BMATH_MINT_HH + +namespace bmath { #include #include @@ -7,11 +9,9 @@ #include #include -namespace bmath { - inline constexpr uint64_t DEFAULT_MOD = 1'000'000'007; -template (DEFAULT_MOD)> +template (DEFAULT_MOD)> requires(M > 0 && DEFAULT_MOD <= std::numeric_limits::max()) class mint { public: @@ -140,7 +140,7 @@ class mint { } }; -template +template requires(M > 0) [[nodiscard]] static constexpr bmath::mint pow(mint base, U exponent) { @@ -175,7 +175,7 @@ template return t; } -template +template requires(M > 0) [[nodiscard]] std::string to_string(mint const number) { return std::to_string(number.get()); diff --git a/tests/test_bmath.cc b/tests/test_bmath.cc index 2fd829c..8f0eb62 100644 --- a/tests/test_bmath.cc +++ b/tests/test_bmath.cc @@ -3,7 +3,7 @@ #include #include -#include "../include/bmath.hh" +#include "../include/bmath/bmath.hh" using namespace bmath; From 58eb8747231ae06f3c7051e96d7cd32ef46d355e Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 30 Aug 2025 19:13:32 -0500 Subject: [PATCH 05/14] fix pre-commit setup --- .pre-commit-config.yaml | 10 +++++----- pyproject.toml | 4 ++-- readme.md | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ef37ed2..160b9cf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ repos: - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v17.0.6 - hooks: - - id: clang-format - args: [--style=file] - files: \.(cc|cpp|cxx|hh|hpp|hxx)$ + rev: v17.0.6 + hooks: + - id: clang-format + args: [--style=file] + files: \.(cc|cpp|cxx|hh|hpp|hxx)$ diff --git a/pyproject.toml b/pyproject.toml index bca982c..d710dc2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,8 @@ [project] name = "bmath" version = "0.1.0" -description = "Add your description here" -readme = "README.md" +description = "Header-Only C++ 23 Math Library" +readme = "readme.md" requires-python = ">=3.11" dependencies = [ "pre-commit>=4.3.0", diff --git a/readme.md b/readme.md index bde468b..70350b5 100644 --- a/readme.md +++ b/readme.md @@ -6,4 +6,4 @@ header-only c++ 23 math library [] sieves [] factorization -[] `std::unsigned_integral` as modulus type +[x] `std::unsigned_integral` as modulus type From b6d154cf4a9303c73dd7650b4163462766fb866f Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 30 Aug 2025 19:14:16 -0500 Subject: [PATCH 06/14] add prettier to readme too --- .pre-commit-config.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 160b9cf..6546b17 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,3 +5,8 @@ repos: - id: clang-format args: [--style=file] files: \.(cc|cpp|cxx|hh|hpp|hxx)$ + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v3.0.0 + hooks: + - id: prettier + files: "^readme\\.md$" From b920d8e0b6c70e593eacfb742a0a135ba1faad3a Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 30 Aug 2025 19:21:39 -0500 Subject: [PATCH 07/14] fix case --- .clang-format | 1 - 1 file changed, 1 deletion(-) diff --git a/.clang-format b/.clang-format index 7be7fb6..0fc1da4 100644 --- a/.clang-format +++ b/.clang-format @@ -35,7 +35,6 @@ AlignConsecutiveShortCaseStatements: Enabled: false AcrossEmptyLines: false AcrossComments: false - AlignCaseArrows: false AlignCaseColons: false AlignConsecutiveTableGenBreakingDAGArgColons: Enabled: false From e3919fe8cd0cfd6830a4c62a636498ca62fceac4 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 30 Aug 2025 19:24:42 -0500 Subject: [PATCH 08/14] another setting --- .clang-format | 1 - 1 file changed, 1 deletion(-) diff --git a/.clang-format b/.clang-format index 0fc1da4..c3743a8 100644 --- a/.clang-format +++ b/.clang-format @@ -80,7 +80,6 @@ AlwaysBreakBeforeMultilineStrings: true AttributeMacros: - __capability BinPackArguments: true -BinPackParameters: BinPack BitFieldColonSpacing: Both BraceWrapping: AfterCaseLabel: false From 17c0c4c32e6c1ce46490a3ae4ac0e302c85b345b Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 30 Aug 2025 19:30:36 -0500 Subject: [PATCH 09/14] use clang-format --- .clang-format | 313 ---------------------------------------- .pre-commit-config.yaml | 2 +- include/bmath/mint.hh | 20 +-- 3 files changed, 11 insertions(+), 324 deletions(-) delete mode 100644 .clang-format diff --git a/.clang-format b/.clang-format deleted file mode 100644 index c3743a8..0000000 --- a/.clang-format +++ /dev/null @@ -1,313 +0,0 @@ ---- -Language: Cpp -AccessModifierOffset: -1 -AlignAfterOpenBracket: Align -AlignArrayOfStructures: None -AlignConsecutiveAssignments: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionPointers: false - PadOperators: true -AlignConsecutiveBitFields: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveDeclarations: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveMacros: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveShortCaseStatements: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCaseColons: false -AlignConsecutiveTableGenBreakingDAGArgColons: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveTableGenCondOperatorColons: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionPointers: false - PadOperators: false -AlignConsecutiveTableGenDefinitionColons: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - AlignFunctionPointers: false - PadOperators: false -AlignEscapedNewlines: Left -AlignOperands: Align -AlignTrailingComments: - Kind: Always - OverEmptyLines: 0 -AllowAllArgumentsOnNextLine: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowBreakBeforeNoexceptSpecifier: Never -AllowShortBlocksOnASingleLine: Never -AllowShortCaseExpressionOnASingleLine: true -AllowShortCaseLabelsOnASingleLine: false -AllowShortCompoundRequirementOnASingleLine: true -AllowShortEnumsOnASingleLine: true -AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: WithoutElse -AllowShortLambdasOnASingleLine: All -AllowShortLoopsOnASingleLine: true -AllowShortNamespacesOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakBeforeMultilineStrings: true -AttributeMacros: - - __capability -BinPackArguments: true -BitFieldColonSpacing: Both -BraceWrapping: - AfterCaseLabel: false - AfterClass: false - AfterControlStatement: Never - AfterEnum: false - AfterExternBlock: false - AfterFunction: false - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - BeforeCatch: false - BeforeElse: false - BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false - SplitEmptyFunction: true - SplitEmptyRecord: true - SplitEmptyNamespace: true -BreakAdjacentStringLiterals: true -BreakAfterAttributes: Leave -BreakAfterJavaFieldAnnotations: false -BreakAfterReturnType: None -BreakArrays: true -BreakBeforeBinaryOperators: None -BreakBeforeConceptDeclarations: Always -BreakBeforeBraces: Attach -BreakBeforeInlineASMColon: OnlyMultiline -BreakBeforeTernaryOperators: true -BreakBinaryOperations: Never -BreakConstructorInitializers: BeforeColon -BreakFunctionDefinitionParameters: false -BreakInheritanceList: BeforeColon -BreakStringLiterals: true -BreakTemplateDeclarations: Yes -ColumnLimit: 80 -CommentPragmas: '^ IWYU pragma:' -CompactNamespaces: false -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -Cpp11BracedListStyle: true -DerivePointerAlignment: true -DisableFormat: false -EmptyLineAfterAccessModifier: Never -EmptyLineBeforeAccessModifier: LogicalBlock -ExperimentalAutoDetectBinPacking: false -FixNamespaceComments: true -ForEachMacros: - - foreach - - Q_FOREACH - - BOOST_FOREACH -IfMacros: - - KJ_IF_MAYBE -IncludeBlocks: Regroup -IncludeCategories: - - Regex: '^' - Priority: 2 - SortPriority: 0 - CaseSensitive: false - - Regex: '^<.*\.h>' - Priority: 1 - SortPriority: 0 - CaseSensitive: false - - Regex: '^<.*' - Priority: 2 - SortPriority: 0 - CaseSensitive: false - - Regex: '.*' - Priority: 3 - SortPriority: 0 - CaseSensitive: false -IncludeIsMainRegex: '([-_](test|unittest))?$' -IncludeIsMainSourceRegex: '' -IndentAccessModifiers: false -IndentCaseBlocks: false -IndentCaseLabels: true -IndentExportBlock: true -IndentExternBlock: AfterExternBlock -IndentGotoLabels: true -IndentPPDirectives: None -IndentRequiresClause: true -IndentWidth: 2 -IndentWrappedFunctionNames: false -InsertBraces: false -InsertNewlineAtEOF: false -InsertTrailingCommas: None -IntegerLiteralSeparator: - Binary: 0 - BinaryMinDigits: 0 - Decimal: 0 - DecimalMinDigits: 0 - Hex: 0 - HexMinDigits: 0 -JavaScriptQuotes: Leave -JavaScriptWrapImports: true -KeepEmptyLines: - AtEndOfFile: false - AtStartOfBlock: false - AtStartOfFile: true -KeepFormFeed: false -LambdaBodyIndentation: Signature -LineEnding: DeriveLF -MacroBlockBegin: '' -MacroBlockEnd: '' -MainIncludeChar: Quote -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -ObjCBinPackProtocolList: Never -ObjCBlockIndentWidth: 2 -ObjCBreakBeforeNestedBlockParam: true -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -PackConstructorInitializers: NextLine -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 1 -PenaltyBreakBeforeMemberAccess: 150 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakOpenParenthesis: 0 -PenaltyBreakScopeResolution: 500 -PenaltyBreakString: 1000 -PenaltyBreakTemplateDeclaration: 10 -PenaltyExcessCharacter: 1000000 -PenaltyIndentedWhitespace: 0 -PenaltyReturnTypeOnItsOwnLine: 200 -PointerAlignment: Left -PPIndentWidth: -1 -QualifierAlignment: Leave -RawStringFormats: - - Language: Cpp - Delimiters: - - cc - - CC - - cpp - - Cpp - - CPP - - 'c++' - - 'C++' - CanonicalDelimiter: '' - BasedOnStyle: google - - Language: TextProto - Delimiters: - - pb - - PB - - proto - - PROTO - EnclosingFunctions: - - EqualsProto - - EquivToProto - - PARSE_PARTIAL_TEXT_PROTO - - PARSE_TEST_PROTO - - PARSE_TEXT_PROTO - - ParseTextOrDie - - ParseTextProtoOrDie - - ParseTestProto - - ParsePartialTestProto - CanonicalDelimiter: pb - BasedOnStyle: google -ReferenceAlignment: Pointer -ReflowComments: Always -RemoveBracesLLVM: false -RemoveEmptyLinesInUnwrappedLines: false -RemoveParentheses: Leave -RemoveSemicolon: false -RequiresClausePosition: OwnLine -RequiresExpressionIndentation: OuterScope -SeparateDefinitionBlocks: Leave -ShortNamespaceLines: 1 -SkipMacroDefinitionBody: false -SortIncludes: CaseSensitive -SortJavaStaticImport: Before -SortUsingDeclarations: LexicographicNumeric -SpaceAfterCStyleCast: false -SpaceAfterLogicalNot: false -SpaceAfterTemplateKeyword: true -SpaceAroundPointerQualifiers: Default -SpaceBeforeAssignmentOperators: true -SpaceBeforeCaseColon: false -SpaceBeforeCpp11BracedList: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeJsonColon: false -SpaceBeforeParens: ControlStatements -SpaceBeforeParensOptions: - AfterControlStatements: true - AfterForeachMacros: true - AfterFunctionDefinitionName: false - AfterFunctionDeclarationName: false - AfterIfMacros: true - AfterOverloadedOperator: false - AfterPlacementOperator: true - AfterRequiresInClause: false - AfterRequiresInExpression: false - BeforeNonEmptyParentheses: false -SpaceBeforeRangeBasedForLoopColon: true -SpaceBeforeSquareBrackets: false -SpaceInEmptyBlock: false -SpacesBeforeTrailingComments: 2 -SpacesInAngles: Never -SpacesInContainerLiterals: true -SpacesInLineCommentPrefix: - Minimum: 1 - Maximum: -1 -SpacesInParens: Never -SpacesInParensOptions: - ExceptDoubleParentheses: false - InCStyleCasts: false - InConditionalStatements: false - InEmptyParentheses: false - Other: false -SpacesInSquareBrackets: false -Standard: Auto -StatementAttributeLikeMacros: - - Q_EMIT -StatementMacros: - - Q_UNUSED - - QT_REQUIRE_VERSION -TableGenBreakInsideDAGArg: DontBreak -TabWidth: 8 -UseTab: Never -VerilogBreakBetweenInstancePorts: true -WhitespaceSensitiveMacros: - - BOOST_PP_STRINGIZE - - CF_SWIFT_NAME - - NS_SWIFT_NAME - - PP_STRINGIZE - - STRINGIZE -WrapNamespaceBodyWithEmptyLines: Leave -... - diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6546b17..37c98ac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ repos: rev: v17.0.6 hooks: - id: clang-format - args: [--style=file] + args: [--style=google] files: \.(cc|cpp|cxx|hh|hpp|hxx)$ - repo: https://github.com/pre-commit/mirrors-prettier rev: v3.0.0 diff --git a/include/bmath/mint.hh b/include/bmath/mint.hh index fc73e2c..14a6ff2 100644 --- a/include/bmath/mint.hh +++ b/include/bmath/mint.hh @@ -11,7 +11,7 @@ namespace bmath { inline constexpr uint64_t DEFAULT_MOD = 1'000'000'007; -template (DEFAULT_MOD)> +template (DEFAULT_MOD)> requires(M > 0 && DEFAULT_MOD <= std::numeric_limits::max()) class mint { public: @@ -25,7 +25,7 @@ class mint { return mint{result}; } - constexpr mint& operator+=(mint const other) const noexcept { + constexpr mint &operator+=(mint const other) const noexcept { value += other.value; return *this; @@ -44,7 +44,7 @@ class mint { return mint{result}; } - constexpr mint& operator*=(mint const other) noexcept { + constexpr mint &operator*=(mint const other) noexcept { value *= other.value; return *this; @@ -62,7 +62,7 @@ class mint { return mint{result}; } - constexpr mint& operator/=(mint const other) noexcept { + constexpr mint &operator/=(mint const other) noexcept { if constexpr (other.get() == 0) { static_assert(false, "Cannot divide by 0"); } else if (other.get() == 0) { @@ -80,7 +80,7 @@ class mint { return mint{result}; } - constexpr mint& operator%=(mint const other) const noexcept { + constexpr mint &operator%=(mint const other) const noexcept { value %= other.value; return *this; @@ -111,7 +111,7 @@ class mint { } template OtherT, OtherT OtherM> - friend std::ostream& operator<<(std::ostream& out, + friend std::ostream &operator<<(std::ostream &out, mint const other) { return out << other.get(); } @@ -140,7 +140,7 @@ class mint { } }; -template +template requires(M > 0) [[nodiscard]] static constexpr bmath::mint pow(mint base, U exponent) { @@ -175,7 +175,7 @@ template return t; } -template +template requires(M > 0) [[nodiscard]] std::string to_string(mint const number) { return std::to_string(number.get()); @@ -187,12 +187,12 @@ template struct std::formatter, CharT> { std::formatter, CharT> inner; - constexpr auto parse(std::basic_format_parse_context& pc) { + constexpr auto parse(std::basic_format_parse_context &pc) { return inner.parse(pc); } template - auto format(bmath::mint const x, Ctx& ctx) const { + auto format(bmath::mint const x, Ctx &ctx) const { std::basic_string tmp; if constexpr (std::same_as) { std::format_to(std::back_inserter(tmp), L"{}", x.get()); From 04a2e769fd12ba7816d5a362383ba219399d723b Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 30 Aug 2025 19:37:06 -0500 Subject: [PATCH 10/14] fix the clang-format in ci --- .github/workflows/ci.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a134173..e588245 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,7 +9,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: sudo apt-get update && sudo apt-get install -y clang-format + - run: | + wget https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.6/clang+llvm-17.0.6-x86_64-linux-gnu-ubuntu-22.04.tar.xz + tar -xf clang+llvm-17.0.6-x86_64-linux-gnu-ubuntu-22.04.tar.xz + sudo cp clang+llvm-17.0.6-x86_64-linux-gnu-ubuntu-22.04/bin/clang-format /usr/local/bin/ - name: Check clang-format run: | set -e @@ -17,7 +20,7 @@ jobs: if [ -z "$FILES" ]; then exit 0; fi clang-format --version for f in $FILES; do - clang-format --dry-run -Werror "$f" + clang-format --style=google --dry-run -Werror "$f" done build-and-test: From 85602da3356b598e6c7fa70cab493478153da349 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 30 Aug 2025 19:39:32 -0500 Subject: [PATCH 11/14] try to fix ci --- .github/workflows/ci.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e588245..2809fe4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,14 +14,7 @@ jobs: tar -xf clang+llvm-17.0.6-x86_64-linux-gnu-ubuntu-22.04.tar.xz sudo cp clang+llvm-17.0.6-x86_64-linux-gnu-ubuntu-22.04/bin/clang-format /usr/local/bin/ - name: Check clang-format - run: | - set -e - FILES=$(git ls-files | grep -E '\.(cc|hh|hpp|cpp|cxx)$' || true) - if [ -z "$FILES" ]; then exit 0; fi - clang-format --version - for f in $FILES; do - clang-format --style=google --dry-run -Werror "$f" - done + run: clang-format --style=google --dry-run -Werror **/*.{hpp,hh,hxx,h,cpp,cc,cxx,c} build-and-test: runs-on: ubuntu-latest @@ -31,7 +24,14 @@ jobs: steps: - uses: actions/checkout@v4 - name: Install compiler - run: sudo apt-get update && sudo apt-get install -y g++ cmake + run: | + sudo apt-get update + sudo apt-get install -y software-properties-common + sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test + sudo apt-get update + sudo apt-get install -y gcc-13 g++-13 cmake + sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 100 + sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 100 - name: Configure CMake run: cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - name: Build From 85383ed7dc907ff8d6c83f4178b56897a19462a7 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 30 Aug 2025 19:42:00 -0500 Subject: [PATCH 12/14] fine --- .github/workflows/ci.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2809fe4..e171705 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,7 +14,15 @@ jobs: tar -xf clang+llvm-17.0.6-x86_64-linux-gnu-ubuntu-22.04.tar.xz sudo cp clang+llvm-17.0.6-x86_64-linux-gnu-ubuntu-22.04/bin/clang-format /usr/local/bin/ - name: Check clang-format - run: clang-format --style=google --dry-run -Werror **/*.{hpp,hh,hxx,h,cpp,cc,cxx,c} + run: | + set -e + FILES=$(git ls-files | grep -E '\.(cc|hh|hpp|cpp|cxx)$' || true) + if [ -z "$FILES" ]; then exit 0; fi + clang-format --style=google --dry-run -Werror **/*.{cc,hh} + clang-format --version + for f in $FILES; do + clang-format --style=google --dry-run -Werror "$f" + done build-and-test: runs-on: ubuntu-latest From f61b5b14c66c61dc0a741a09b19f05e9828f4685 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 30 Aug 2025 19:42:43 -0500 Subject: [PATCH 13/14] dont make friend a template --- include/bmath/mint.hh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/bmath/mint.hh b/include/bmath/mint.hh index 14a6ff2..da50055 100644 --- a/include/bmath/mint.hh +++ b/include/bmath/mint.hh @@ -110,9 +110,7 @@ class mint { return get() == static_cast(other.get()); } - template OtherT, OtherT OtherM> - friend std::ostream &operator<<(std::ostream &out, - mint const other) { + friend std::ostream &operator<<(std::ostream &out, mint const other) { return out << other.get(); } From d8c739695f4a33def0f0b2ebfcecffa68c2b32ab Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 30 Aug 2025 19:48:24 -0500 Subject: [PATCH 14/14] fix --- .github/workflows/ci.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e171705..1b94d56 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,7 +18,6 @@ jobs: set -e FILES=$(git ls-files | grep -E '\.(cc|hh|hpp|cpp|cxx)$' || true) if [ -z "$FILES" ]; then exit 0; fi - clang-format --style=google --dry-run -Werror **/*.{cc,hh} clang-format --version for f in $FILES; do clang-format --style=google --dry-run -Werror "$f"