项目作者: VecPP

项目描述 :
Compile-time arbitrary arithmetic types
高级语言: C++
项目地址: git://github.com/VecPP/ap_math.git
创建时间: 2018-09-10T17:52:02Z
项目社区:https://github.com/VecPP/ap_math

开源协议:Other

下载


ap_math

simple compile-time abitrary-sized artihmetic types.

Ap_int<>

Behaves like native types as much as humanly possible.

  • Arithmetic
  • std::numeric_limits<> specialization.
  • std::ostream support.

The only real difference with native types is that numbers greater than the largest uint64_t cannot be initialized using integre literals, so you’ll have to use the string-based constructor (which is constexpr too!).

Example:

  1. #include "vecpp/ap_math/ap_int.h"
  2. #include "vecpp/ap_math/limits.h"
  3. #include <iostream>
  4. int main() {
  5. vecpp::Ap_int<80> a{"1234567890123456789012345"};
  6. vecpp::Ap_int<80> b = 12;
  7. a = a * b;
  8. std::cout << a << "\n";
  9. // ap_math also support very small ints for completeness
  10. vecpp::Ap_int<3> a = 1;
  11. vecpp::Ap_int<3> b = 2;
  12. for(int i = 0 ; i < 20; ++i) {
  13. a = a + b;
  14. std::cout << a << "\n";
  15. }
  16. // std::numeric_limits<>
  17. std::cout << "the largest possible 265 bits int: " << std::numeric_limits<vecpp::Ap_int<265>>::max() << "\n";
  18. return 0;
  19. }

Why?

In order to hit precision objectives in cste_math,
we need to be able to compute values of sizes that are not available with the core types.

Acknowledgements

The implementation details are heavily inspired from llvm::APInt and llvm::APFloat.