commit
771751d9c0
14 changed files with 227 additions and 508 deletions
321
.clang-format
321
.clang-format
|
|
@ -1,321 +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
|
|
||||||
AlignFunctionDeclarations: false
|
|
||||||
AlignFunctionPointers: false
|
|
||||||
PadOperators: false
|
|
||||||
AlignConsecutiveDeclarations:
|
|
||||||
Enabled: false
|
|
||||||
AcrossEmptyLines: false
|
|
||||||
AcrossComments: false
|
|
||||||
AlignCompound: false
|
|
||||||
AlignFunctionDeclarations: true
|
|
||||||
AlignFunctionPointers: false
|
|
||||||
PadOperators: false
|
|
||||||
AlignConsecutiveMacros:
|
|
||||||
Enabled: false
|
|
||||||
AcrossEmptyLines: false
|
|
||||||
AcrossComments: false
|
|
||||||
AlignCompound: false
|
|
||||||
AlignFunctionDeclarations: false
|
|
||||||
AlignFunctionPointers: false
|
|
||||||
PadOperators: false
|
|
||||||
AlignConsecutiveShortCaseStatements:
|
|
||||||
Enabled: false
|
|
||||||
AcrossEmptyLines: false
|
|
||||||
AcrossComments: false
|
|
||||||
AlignCaseArrows: false
|
|
||||||
AlignCaseColons: false
|
|
||||||
AlignConsecutiveTableGenBreakingDAGArgColons:
|
|
||||||
Enabled: false
|
|
||||||
AcrossEmptyLines: false
|
|
||||||
AcrossComments: false
|
|
||||||
AlignCompound: false
|
|
||||||
AlignFunctionDeclarations: false
|
|
||||||
AlignFunctionPointers: false
|
|
||||||
PadOperators: false
|
|
||||||
AlignConsecutiveTableGenCondOperatorColons:
|
|
||||||
Enabled: false
|
|
||||||
AcrossEmptyLines: false
|
|
||||||
AcrossComments: false
|
|
||||||
AlignCompound: false
|
|
||||||
AlignFunctionDeclarations: false
|
|
||||||
AlignFunctionPointers: false
|
|
||||||
PadOperators: false
|
|
||||||
AlignConsecutiveTableGenDefinitionColons:
|
|
||||||
Enabled: false
|
|
||||||
AcrossEmptyLines: false
|
|
||||||
AcrossComments: false
|
|
||||||
AlignCompound: false
|
|
||||||
AlignFunctionDeclarations: 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
|
|
||||||
BinPackParameters: BinPack
|
|
||||||
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: '^<ext/.*\.h>'
|
|
||||||
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
|
|
||||||
...
|
|
||||||
|
|
||||||
27
.github/workflows/ci.yaml
vendored
27
.github/workflows/ci.yaml
vendored
|
|
@ -9,7 +9,10 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- 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
|
- name: Check clang-format
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -e
|
||||||
|
|
@ -17,14 +20,28 @@ jobs:
|
||||||
if [ -z "$FILES" ]; then exit 0; fi
|
if [ -z "$FILES" ]; then exit 0; fi
|
||||||
clang-format --version
|
clang-format --version
|
||||||
for f in $FILES; do
|
for f in $FILES; do
|
||||||
clang-format --dry-run -Werror "$f"
|
clang-format --style=google --dry-run -Werror "$f"
|
||||||
done
|
done
|
||||||
|
|
||||||
build-and-test:
|
build-and-test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
build_type: [Release]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Install compiler
|
- name: Install compiler
|
||||||
run: sudo apt-get update && sudo apt-get install -y g++
|
run: |
|
||||||
- name: Debug tests (asserts + sanitizers)
|
sudo apt-get update
|
||||||
run: make test MODE=debug
|
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
|
||||||
|
run: cmake --build build
|
||||||
|
- name: Test
|
||||||
|
run: ctest --test-dir build --output-on-failure
|
||||||
|
|
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,4 +1,6 @@
|
||||||
build/
|
build/
|
||||||
|
build-release/
|
||||||
|
.cache/
|
||||||
*.o
|
*.o
|
||||||
*.a
|
*.a
|
||||||
*.swp
|
*.swp
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/pre-commit/mirrors-clang-format
|
- repo: https://github.com/pre-commit/mirrors-clang-format
|
||||||
rev: v17.0.6
|
rev: v17.0.6
|
||||||
hooks:
|
hooks:
|
||||||
- id: clang-format
|
- id: clang-format
|
||||||
args: [--style=file]
|
args: [--style=google]
|
||||||
files: \.(cc|cpp|cxx|hh|hpp|hxx)$
|
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$"
|
||||||
|
|
|
||||||
81
CMakeLists.txt
Normal file
81
CMakeLists.txt
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:include>)
|
||||||
|
|
||||||
|
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
|
||||||
|
-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)
|
||||||
|
|
@ -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
|
|
||||||
6
include/bmath/bmath.hh
Normal file
6
include/bmath/bmath.hh
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef BMATH_BMATH_HH
|
||||||
|
#define BMATH_BMATH_HH
|
||||||
|
|
||||||
|
#include "bmath/mint.hh"
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#ifndef BMATH_HEADER_ONLY_MATH_LIB
|
#ifndef BMATH_MINT_HH
|
||||||
#define BMATH_HEADER_ONLY_MATH_LIB
|
#define BMATH_MINT_HH
|
||||||
|
|
||||||
|
namespace bmath {
|
||||||
|
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
@ -7,8 +9,6 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace bmath {
|
|
||||||
|
|
||||||
inline constexpr uint64_t DEFAULT_MOD = 1'000'000'007;
|
inline constexpr uint64_t DEFAULT_MOD = 1'000'000'007;
|
||||||
|
|
||||||
template <std::integral T, T M = static_cast<T>(DEFAULT_MOD)>
|
template <std::integral T, T M = static_cast<T>(DEFAULT_MOD)>
|
||||||
|
|
@ -25,7 +25,7 @@ class mint {
|
||||||
return mint<T, M>{result};
|
return mint<T, M>{result};
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr mint& operator+=(mint const other) const noexcept {
|
constexpr mint &operator+=(mint const other) const noexcept {
|
||||||
value += other.value;
|
value += other.value;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
|
|
@ -44,7 +44,7 @@ class mint {
|
||||||
return mint<T, M>{result};
|
return mint<T, M>{result};
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr mint& operator*=(mint const other) noexcept {
|
constexpr mint &operator*=(mint const other) noexcept {
|
||||||
value *= other.value;
|
value *= other.value;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
|
|
@ -62,7 +62,7 @@ class mint {
|
||||||
return mint<T, M>{result};
|
return mint<T, M>{result};
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr mint& operator/=(mint const other) noexcept {
|
constexpr mint &operator/=(mint const other) noexcept {
|
||||||
if constexpr (other.get() == 0) {
|
if constexpr (other.get() == 0) {
|
||||||
static_assert(false, "Cannot divide by 0");
|
static_assert(false, "Cannot divide by 0");
|
||||||
} else if (other.get() == 0) {
|
} else if (other.get() == 0) {
|
||||||
|
|
@ -80,7 +80,7 @@ class mint {
|
||||||
return mint<T, M>{result};
|
return mint<T, M>{result};
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr mint& operator%=(mint const other) const noexcept {
|
constexpr mint &operator%=(mint const other) const noexcept {
|
||||||
value %= other.value;
|
value %= other.value;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
|
|
@ -110,9 +110,7 @@ class mint {
|
||||||
return get() == static_cast<T>(other.get());
|
return get() == static_cast<T>(other.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <std::convertible_to<T> OtherT, OtherT OtherM>
|
friend std::ostream &operator<<(std::ostream &out, mint const other) {
|
||||||
friend std::ostream& operator<<(std::ostream& out,
|
|
||||||
mint<OtherT, OtherM> const other) {
|
|
||||||
return out << other.get();
|
return out << other.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -187,12 +185,12 @@ template <class CharT, std::integral T, T M>
|
||||||
struct std::formatter<bmath::mint<T, M>, CharT> {
|
struct std::formatter<bmath::mint<T, M>, CharT> {
|
||||||
std::formatter<std::basic_string_view<CharT>, CharT> inner;
|
std::formatter<std::basic_string_view<CharT>, CharT> inner;
|
||||||
|
|
||||||
constexpr auto parse(std::basic_format_parse_context<CharT>& pc) {
|
constexpr auto parse(std::basic_format_parse_context<CharT> &pc) {
|
||||||
return inner.parse(pc);
|
return inner.parse(pc);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Ctx>
|
template <class Ctx>
|
||||||
auto format(bmath::mint<T, M> const x, Ctx& ctx) const {
|
auto format(bmath::mint<T, M> const x, Ctx &ctx) const {
|
||||||
std::basic_string<CharT> tmp;
|
std::basic_string<CharT> tmp;
|
||||||
if constexpr (std::same_as<CharT, wchar_t>) {
|
if constexpr (std::same_as<CharT, wchar_t>) {
|
||||||
std::format_to(std::back_inserter(tmp), L"{}", x.get());
|
std::format_to(std::back_inserter(tmp), L"{}", x.get());
|
||||||
108
makefile
108
makefile
|
|
@ -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
|
|
||||||
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
[project]
|
[project]
|
||||||
name = "bmath"
|
name = "bmath"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
description = "Add your description here"
|
description = "Header-Only C++ 23 Math Library"
|
||||||
readme = "README.md"
|
readme = "readme.md"
|
||||||
requires-python = ">=3.11"
|
requires-python = ">=3.11"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"pre-commit>=4.3.0",
|
"pre-commit>=4.3.0",
|
||||||
|
|
|
||||||
|
|
@ -6,4 +6,4 @@ header-only c++ 23 math library
|
||||||
|
|
||||||
[] sieves
|
[] sieves
|
||||||
[] factorization
|
[] factorization
|
||||||
[] `std::unsigned_integral` as modulus type
|
[x] `std::unsigned_integral` as modulus type
|
||||||
|
|
|
||||||
17
tests/CMakeLists.txt
Normal file
17
tests/CMakeLists.txt
Normal file
|
|
@ -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)
|
||||||
75
tests/test_bmath.cc
Normal file
75
tests/test_bmath.cc
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <format>
|
||||||
|
|
||||||
|
#include "../include/bmath/bmath.hh"
|
||||||
|
|
||||||
|
using namespace bmath;
|
||||||
|
|
||||||
|
TEST(MintTest, BasicConstruction) {
|
||||||
|
mint<uint64_t> four{4};
|
||||||
|
|
||||||
|
static_assert(std::is_trivially_copyable_v<mint<uint64_t>>);
|
||||||
|
|
||||||
|
EXPECT_EQ(four.get(), 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MintTest, Formatting) {
|
||||||
|
mint<uint64_t> 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<uint64_t> a{3};
|
||||||
|
mint<uint64_t> b{5};
|
||||||
|
|
||||||
|
auto result = a + b;
|
||||||
|
EXPECT_EQ(result.get(), 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MintTest, Subtraction) {
|
||||||
|
mint<uint64_t> a{10};
|
||||||
|
mint<uint64_t> b{3};
|
||||||
|
|
||||||
|
auto result = a - b;
|
||||||
|
EXPECT_EQ(result.get(), 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MintTest, Multiplication) {
|
||||||
|
mint<uint64_t> a{6};
|
||||||
|
mint<uint64_t> b{7};
|
||||||
|
|
||||||
|
auto result = a * b;
|
||||||
|
EXPECT_EQ(result.get(), 42);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(MintTest, Modular) {
|
||||||
|
constexpr uint64_t mod = 13;
|
||||||
|
mint<uint64_t, mod> a{15};
|
||||||
|
|
||||||
|
EXPECT_EQ(a.get(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(PowerTest, BasicPower) {
|
||||||
|
mint<uint64_t> base{2};
|
||||||
|
auto result = pow(base, 3);
|
||||||
|
EXPECT_EQ(result.get(), 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(PowerTest, PowerOfOne) {
|
||||||
|
mint<uint64_t> base{5};
|
||||||
|
auto result = pow(base, 0);
|
||||||
|
EXPECT_EQ(result.get(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(PowerTest, PowerOfZero) {
|
||||||
|
mint<uint64_t> base{0};
|
||||||
|
auto result = pow(base, 5);
|
||||||
|
EXPECT_EQ(result.get(), 0);
|
||||||
|
}
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
#include <cassert>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "../include/bmath.hh"
|
|
||||||
|
|
||||||
using namespace bmath;
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
mint<uint64_t> four{4};
|
|
||||||
|
|
||||||
// should be trivially copyable
|
|
||||||
static_assert(is_trivially_copyable_v<mint<uint64_t>>);
|
|
||||||
|
|
||||||
// should be able to format
|
|
||||||
auto formatted = format("{}\n", four);
|
|
||||||
|
|
||||||
// and use to_string
|
|
||||||
formatted = to_string(four);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue