Skip to content

Commit

Permalink
rename to decimal (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
geseq authored Dec 24, 2023
1 parent 3cf376c commit ce48e56
Show file tree
Hide file tree
Showing 4 changed files with 443 additions and 438 deletions.
19 changes: 12 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)

project(udecimal LANGUAGES CXX)
set(CPP_DECIMAL cpp-decimal)

project(${CPP_DECIMAL} LANGUAGES CXX)
enable_testing()

set(CMAKE_CXX_STANDARD 17)
if(NOT "${CMAKE_CXX_STANDARD}")
set(CMAKE_CXX_STANDARD 17)
endif()
message(STATUS "CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}")

add_library(udecimal INTERFACE)
target_sources(udecimal INTERFACE include/udecimal.hpp)
target_include_directories(udecimal INTERFACE include/)
add_library(${CPP_DECIMAL} INTERFACE)
target_sources(${CPP_DECIMAL} INTERFACE include/decimal.hpp)
target_include_directories(${CPP_DECIMAL} INTERFACE include/)

option(ENABLE_TESTING "Enable test target generation" OFF)
option(BENCHMARK_ENABLE_TESTING "run benchmarks" OFF)
Expand All @@ -27,7 +32,7 @@ if (ENABLE_TESTING)
message("Adding test: " ${test_name})
add_executable(${test_name} ${PROJECT_SOURCE_DIR}/test/${test_name})
target_link_libraries(${test_name} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${test_name} PRIVATE udecimal gtest gtest_main)
target_link_libraries(${test_name} PRIVATE ${CPP_DECIMAL} gtest gtest_main)
add_test(${test_name} ${test_name})
set_property(TEST ${test_name} PROPERTY LABELS "test")
ENDFOREACH ()
Expand All @@ -47,7 +52,7 @@ if (ENABLE_TESTING)
get_filename_component(test_name ${test} NAME)
message("Adding bench: " ${test_name})
add_executable(${test_name} ${PROJECT_SOURCE_DIR}/bench/${test_name})
target_link_libraries(${test_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT} benchmark::benchmark udecimal)
target_link_libraries(${test_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT} benchmark::benchmark ${CPP_DECIMAL})
add_test(${test_name} ${test_name})
set_property(TEST ${test_name} PROPERTY LABELS "bench")
list(APPEND ignore_tests ${test_name})
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
# cpp-udecimal
# cpp-decimal

A fixed place signed/unsigned numeric library. Unsigned by default.

## Usage

```
// 8 decimal places, unsigned
auto f = udecimal::U8("123.456"); // 123.456
auto f = udecimal::U8(123456, 3); // 123.456
auto f = udecimal::U8::FromExp(123456, -3); // 123.456
auto f = udecimal::U8(123.456); // 123.456
auto f = decimal::U8("123.456"); // 123.456
auto f = decimal::U8(123456, 3); // 123.456
auto f = decimal::U8::FromExp(123456, -3); // 123.456
auto f = decimal::U8(123.456); // 123.456
// 9 decimal places, unsigned
auto f = udecimal::U9("123.456"); // 123.456
auto f = udecimal::U9(123456, 3); // 123.456
auto f = udecimal::U9::FromExp(123456, -3); // 123.456
auto f = udecimal::U9(123.456); // 123.456
auto f = decimal::U9("123.456"); // 123.456
auto f = decimal::U9(123456, 3); // 123.456
auto f = decimal::U9::FromExp(123456, -3); // 123.456
auto f = decimal::U9(123.456); // 123.456
// 9 decimal places, signed
auto f = udecimal::I9("123.456"); // 123.456
auto f = udecimal::I9(123456, 3); // 123.456
auto f = udecimal::I9::FromExp(123456, -3); // 123.456
auto f = udecimal::I9(123.456); // 123.456
auto f = decimal::I9("123.456"); // 123.456
auto f = decimal::I9(123456, 3); // 123.456
auto f = decimal::I9::FromExp(123456, -3); // 123.456
auto f = decimal::I9(123.456); // 123.456
// Convert from one precision level to another
auto g = f.convert_precision<2>(); // 123.45
// Alternatively, 8 decimal places, unsigned
auto f = udecimal::Decimal<8, udecimal::Unsigned>("123.456"); // 123.456
auto f = decimal::Decimal<8, decimal::Unsigned>("123.456"); // 123.456
// Alternatively, 8 decimal places, signed
auto f = udecimal::Decimal<8, udecimal::Signed>("123.456"); // 123.456
auto f = decimal::Decimal<8, decimal::Signed>("123.456"); // 123.456
```
10 changes: 5 additions & 5 deletions include/udecimal.hpp → include/decimal.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef UDECIMAL_H
#define UDECIMAL_H
#ifndef CPP_DECIMAL_H
#define CPP_DECIMAL_H

#include <sys/types.h>

Expand All @@ -16,7 +16,7 @@
#include <type_traits>
#include <vector>

namespace udecimal {
namespace decimal {

#if defined(__GNUC__) || defined(__clang__)
#define likely(x) __builtin_expect(!!(x), 1)
Expand Down Expand Up @@ -687,6 +687,6 @@ using I15 = Decimal<15, Signed>;
using I16 = Decimal<16, Signed>;
using I17 = Decimal<17, Signed>;

} // namespace udecimal
} // namespace decimal

#endif // UDECIMAL_H
#endif // CPP_DECIMAL_H
Loading

0 comments on commit ce48e56

Please sign in to comment.