Skip to content

Commit

Permalink
use placeholder types
Browse files Browse the repository at this point in the history
  • Loading branch information
DerThorsten committed Dec 10, 2024
1 parent d4de2d8 commit 54dd0f2
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 38 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
matrix:
runs-on: [windows-latest]
toolchain:
- {compiler: msvc, date-polyfill: 'ON', boost-multiprecision: 'ON'}
- {compiler: msvc, date-polyfill: 'OFF', boost-multiprecision: 'ON'}
- {compiler: clang, date-polyfill: 'ON', version: 18, boost-multiprecision: 'OFF'}
- {compiler: clang, date-polyfill: 'OFF', version: 18, boost-multiprecision: 'OFF'}
- {compiler: msvc, date-polyfill: 'ON', use-large-int-placeholders: 'ON'}
- {compiler: msvc, date-polyfill: 'OFF', use-large-int-placeholders: 'ON'}
- {compiler: clang, date-polyfill: 'ON', version: 18, use-large-int-placeholders: 'OFF'}
- {compiler: clang, date-polyfill: 'OFF', version: 18, use-large-int-placeholders: 'OFF'}
target-arch:
- {
name: "Win64",
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
if: matrix.target-arch.name == 'Win32'
run: |
vcpkg install --triplet=x86-windows
- name: Set conda environment
if: matrix.target-arch.name == 'Win64'
uses: mamba-org/setup-micromamba@main
Expand Down Expand Up @@ -175,7 +175,7 @@ jobs:
-DCMAKE_INSTALL_PREFIX=$SPARROW_INSTALL_PREFIX \
-DBUILD_TESTS=ON \
-DBUILD_EXAMPLES=ON \
-DUSE_BOOST_MULTIPRECISION=${{matrix.toolchain.boost-multiprecision}} \
-DUSE_LARGE_INT_PLACEHOLDERS=${{matrix.toolchain.use-large-int-placeholders}} \
-DUSE_DATE_POLYFILL=${{matrix.toolchain.date-polyfill}} \
$GENERATOR_EXTRA_FLAGS \
$SPARROW_CHECKS \
Expand Down
10 changes: 4 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ OPTION(BUILD_TESTS "Build sparrow test suite" OFF)
OPTION(BUILD_DOCS "Build sparrow documentation" OFF)
OPTION(BUILD_EXAMPLES "Build sparrow examples" OFF)
OPTION(USE_DATE_POLYFILL "Use date polyfill implementation" ON)
OPTION(USE_BOOST_MULTIPRECISION "Use boost multiprecision" OFF)
OPTION(DISABLE_LARGE_INTEGER_DECIMALS "Disable big integer decimals" OFF)
OPTION(USE_LARGE_INT_PLACEHOLDERS "use types without api for big integers" OFF)

OPTION(SPARROW_TARGET_32BIT "Test 32bit support" OFF)

Expand Down Expand Up @@ -133,10 +132,9 @@ if (USE_DATE_POLYFILL)
add_compile_definitions(SPARROW_USE_DATE_POLYFILL)
endif()

if(USE_BOOST_MULTIPRECISION)
find_package(Boost 1.70 REQUIRED)
list(APPEND SPARROW_INTERFACE_DEPENDENCIES Boost::boost)
add_compile_definitions(SPARROW_USE_BOOST_MULTIPRECISION)
if(USE_LARGE_INT_PLACEHOLDERS)

add_compile_definitions(SPARROW_USE_LARGE_INT_PLACEHOLDERS)
endif()

if (DISABLE_LARGE_INTEGER_DECIMALS)
Expand Down
2 changes: 2 additions & 0 deletions include/sparrow/layout/decimal_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ namespace sparrow

// the integral value type used to store the bits
using storage_type = typename T::integer_type;
static_assert(sizeof(storage_type) == 4 || sizeof(storage_type) == 8 || sizeof(storage_type) == 16 || sizeof(storage_type) == 32,
"The storage type must be an integral type of size 4, 8, 16 or 32 bytes");

using bitmap_type = typename base_type::bitmap_type;
using bitmap_const_reference = typename base_type::bitmap_const_reference;
Expand Down
15 changes: 8 additions & 7 deletions include/sparrow/utils/decimal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace sparrow
{
public:
using integer_type = T;

decimal()
: m_value(0)
, m_scale(0)
Expand All @@ -35,8 +36,8 @@ namespace sparrow
{
}

// operator ==
bool operator==(const decimal& other) const

bool operator==(const decimal& other) const
{
return m_value == other.m_value && m_scale == other.m_scale;
}
Expand All @@ -47,21 +48,21 @@ namespace sparrow
return !(*this == other);
}

explicit operator float() const
explicit operator float() const requires(!is_int_placeholder_v<T>)
{
return convert_to_floating_point<float>();
}
explicit operator double() const
explicit operator double() const requires(!is_int_placeholder_v<T>)
{
return convert_to_floating_point<double>();
}
explicit operator long double() const
explicit operator long double() const requires(!is_int_placeholder_v<T>)
{
return convert_to_floating_point<long double>();
}

// convert to string
explicit operator std::string() const
explicit operator std::string() const requires(!is_int_placeholder_v<T>)
{
std::stringstream ss;
ss << m_value;
Expand Down Expand Up @@ -115,7 +116,7 @@ namespace sparrow

private:
template<class FLOAT_TYPE>
FLOAT_TYPE convert_to_floating_point() const
FLOAT_TYPE convert_to_floating_point() const requires(!is_int_placeholder_v<T>)
{
using to_type = FLOAT_TYPE;
if constexpr( std::is_same_v<T, int256_t> )
Expand Down
53 changes: 40 additions & 13 deletions include/sparrow/utils/large_int.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#pragma once

#ifndef SPARROW_DISABLE_LARGE_INTEGER_DECIMALS

#if SPARROW_USE_BOOST_MULTIPRECISION
#include <boost/multiprecision/cpp_int.hpp>
#else
#ifndef SPARROW_USE_LARGE_INT_PLACEHOLDERS

// disabe warnings -Wold-style-cast sign-conversion for clang and gcc
#if defined(__clang__) || defined(__GNUC__)
Expand All @@ -17,8 +13,7 @@
#include <sparrow/details/3rdparty/large_integers/int128_t.hpp>
#include <sparrow/details/3rdparty/large_integers/int256_t.hpp>


#ifdef __GNUC__
#if defined(__clang__) || defined(__GNUC__)
#pragma GCC diagnostic pop
#endif

Expand All @@ -29,10 +24,44 @@

namespace sparrow
{
#if SPARROW_USE_BOOST_MULTIPRECISION
using int128_t = boost::multiprecision::int128_t;
using int256_t = boost::multiprecision::int256_t;


#ifdef SPARROW_USE_LARGE_INT_PLACEHOLDERS
constexpr bool large_int_placeholders = true;

template<class T>
constexpr bool is_int_placeholder_v = std::is_same_v<T, int128_t> || std::is_same_v<T, int256_t>;

struct int128_t
{
uint64_t words[2];
bool operator == (const int128_t& other) const
{
return words[0] == other.words[0] && words[1] == other.words[1];
}
bool operator != (const int128_t& other) const
{
return !(*this == other);
}
};
struct int256_t
{
uint64_t words[4];
bool operator == (const int256_t& other) const
{
return words[0] == other.words[0] && words[1] == other.words[1] && words[2] == other.words[2] && words[3] == other.words[3];
}
bool operator != (const int256_t& other) const
{
return !(*this == other);
}
};
#else

template<class T>
constexpr bool is_int_placeholder_v = false;

constexpr bool large_int_placeholders = false;
using int128_t = primesum::int128_t;
using int256_t = primesum::int256_t;

Expand Down Expand Up @@ -61,6 +90,4 @@ namespace sparrow
return stream;
}
#endif
} // namespace sparrow

#endif // SPARROW_DISABLE_LARGE_INTEGER_DECIMALS
} // namespace sparrow
2 changes: 1 addition & 1 deletion test/test_decimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace sparrow
using testing_types = std::tuple<
int32_t
,int64_t
#ifndef SPARROW_DISABLE_LARGE_INTEGER_DECIMALS
#ifndef SPARROW_USE_LARGE_INT_PLACEHOLDERS
,int128_t
,int256_t
#endif
Expand Down
10 changes: 6 additions & 4 deletions test/test_decimal_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ namespace sparrow
{

using integer_types = std::tuple<
std::int32_t,
std::int64_t,
int128_t,
int256_t
std::int32_t
,std::int64_t
#ifndef SPARROW_USE_LARGE_INT_PLACEHOLDERS
,int128_t
,int256_t
#endif
>;


Expand Down
1 change: 0 additions & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"dependencies": [
"doctest",
"boost",
"date",
{
"name": "vcpkg-tool-ninja",
Expand Down

0 comments on commit 54dd0f2

Please sign in to comment.