Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numeric Type Implementation #45

Closed
18 tasks done
bigerl opened this issue Jul 11, 2022 · 3 comments
Closed
18 tasks done

Numeric Type Implementation #45

bigerl opened this issue Jul 11, 2022 · 3 comments
Assignees

Comments

@bigerl
Copy link
Collaborator

bigerl commented Jul 11, 2022

Implemented Types:

  • xsd:decimal -> 128 bit decimal double
    • xsd:integer -> int128_t
      • xsd:long -> int64_t
        • xsd:int -> int32_t
          • xsd:short -> int16_t
            • xsd:byte -> int8_t
      • xsd:nonNegativeInteger -> uint128_t
        • xsd:positiveInteger -> -> uint128_t (or wrapper)
        • xsd:unisngedLong -> uint64_t
          • xsd:unsigendInt -> uint32_t
            • xsd:unsignedShort -> uint16_t
              • xsd:unsignedByte -> uint8_t
      • xsd:nonPostiveInteger -> int128_t (or wrapper)
        • xsd:negativeInteger -> int128_t (or wrapper)
  • xsd:float -> float
  • xsd:double -> double
  • owl:rational -> ?
  • owl:real -> ?

Ideal would be a library with:

  • runtime arbitrary precision
  • support for basic operations +-*/...
  • support for Integers and Decimals
  • support for nonNegative = unsigned integer
  • explicit support for positiveInteger, nonPostiveInteger, negativeInteger is not required (use Integer or write wrapper)
  • support for fancy pointers and custom allocators

Options for arbitrary precision types:

Options for arbitrary precision floating decimals:

Starting Points for own implementations could be:

signature could be something like:

template<class Allocator = std::allocator<uint32_t>>
class Integer {
    using ptr_type = typename std::allocator_traits<Allocator>::pointer;
    std::size_t count_;
    union {
        size_t small;
        ptr_type big;
    };
   Allocator allocator_;

public:
    consteval Integer() : count_(0), small(0) {}

    Integer(std::string_view str_repr, Allocator const &alloc = Allocator()), allocator_(alloc) {
        std::vector<uint32_t> x{alloc};
        uint32_t buffer[32] = {};
        count_ = parse(str_repr, buffer);
        switch (count_) {
            case 0UL:
                small = {};
                break;
            case 1UL:
                small = buffer[0];
                break;
            case 2UL:
                small = buffer[0] | (uint64_t(buffer[1]) << 32);
                break;
            default: {
                big = std::allocator_traits<Allocator>::allocate(allocator_, count_);
                std::memcpy(std::to_address(big), buffer, sizeof(uint32_t) * count_);
            }
        }
    }
}

This needs more research

@bigerl bigerl changed the title Decimal: do not rely on double Numeric Type Implementation Aug 10, 2022
@Clueliss
Copy link
Collaborator

Implementation takes place in branch feature/numeric-types.

I am currently using boost::multiprecision for xsd:decimal, xsd:integer, xsd:nonNegativeInteger (rational can also be implemented using it). This is by no means a final decision; it was just really easy to integrate into cmake and covers all our needs. But if there is anything wrong with the library then I will obviously change it to something different.

@Clueliss
Copy link
Collaborator

#64 needs to be fixed first
alternatively: actually rely on 128bit integers instead of ap ones; and accept the standard violation by utilizing modular arithmetic, and incorrectly implementing xsd:positiveInteger and xsd:negativeInteger by allowing 0 values.

@Clueliss
Copy link
Collaborator

#82

@Clueliss Clueliss closed this as completed Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants