22 * Copyright © 2017–2025 VargaLABS, Toronto, ON, Canada 🇨🇦 */
33
44#pragma once
5- #include < stdfloat>
65#include < format>
76#include < iostream>
87#include < algorithm>
1615#include < bid_functions.h>
1716#include < dfp754.h>
1817
18+ #if defined(__linux__)
19+ #define sigma_has_bid128 1
20+ #else
21+ #define sigma_has_bid128 0
22+ #endif
23+
1924#ifndef BID32_MAX_PRINTED_DIGITS
2025 #define BID32_MAX_PRINTED_DIGITS 20
2126#endif
2227
2328#ifndef BID64_MAX_PRINTED_DIGITS
2429 #define BID64_MAX_PRINTED_DIGITS 40
2530#endif
26-
27- #ifndef BID128_MAX_PRINTED_DIGITS
28- #define BID128_MAX_PRINTED_DIGITS 80
29- #endif
31+ #if sigma_has_bid128
32+ #ifndef BID128_MAX_PRINTED_DIGITS
33+ #define BID128_MAX_PRINTED_DIGITS 80
34+ #endif
35+ #endif
3036
3137namespace math ::bid {
3238 enum struct category : unsigned char {
@@ -133,6 +139,7 @@ namespace math::bid {
133139 default : return print (kind != category::positive, mantissa, exponent, buffer.data (), buffer.size ());
134140 }
135141 }
142+ #if sigma_has_bid128
136143 inline std::string display_bid128 (BID_UINT128 bid) {
137144 char buf[200 ]{};
138145 unsigned int flags = 0 ;
@@ -142,12 +149,14 @@ namespace math::bid {
142149 inline BID_UINT128 uint128_to_bid128 (BID_UINT128 significand, int exponent) {
143150 BID_UINT128 value;
144151 return value;
145- }
152+ }
153+ #endif
146154}
147155
148156namespace math {
149- using uint128_t = BID_UINT128;
150-
157+ #if sigma_has_bid128
158+ using uint128_t = BID_UINT128;
159+ #endif
151160 template <class T > struct bid_t {
152161 bid_t (T value) : value(value){}
153162 operator T (){ return value; }
@@ -196,7 +205,7 @@ namespace math {
196205 template <> uint64_t str2bid (std::string_view str){ unsigned int flags; std::string tmp{str}; return __bid64_from_string (const_cast <char *>(tmp.data ()), 0 , &flags); }
197206 template <> uint64_t str2bid (const std::string& str){ unsigned int flags; return __bid64_from_string (const_cast <char *>(str.data ()), 0 , &flags); }
198207 template <> std::string bid2str (uint64_t bid){ return bid::display_bid64 (bid); };
199-
208+ # if sigma_has_bid128
200209 template <> uint128_t bid2dpd (uint128_t bid){ return __bid_to_dpd128 (bid); }
201210 template <> uint128_t dpd2bid (uint128_t dpd){ return __bid_dpd_to_bid128 (dpd); }
202211 template <> uint128_t uint2bid (uint128_t significand, int exponent){ return bid::uint128_to_bid128 (significand, exponent); }
@@ -208,6 +217,7 @@ namespace math {
208217 template <> uint128_t str2bid (std::string_view str){ unsigned int flags; std::string tmp{str}; return __bid128_from_string (const_cast <char *>(tmp.data ()), 0 , &flags); }
209218 template <> uint128_t str2bid (const std::string& str){ unsigned int flags; return __bid128_from_string (const_cast <char *>(str.data ()), 0 , &flags); }
210219 template <> std::string bid2str (uint128_t bid){ return bid::display_bid128 (bid); };
220+ #endif
211221 }
212222
213223 // operator defintions
@@ -243,7 +253,9 @@ namespace math {
243253
244254 sigma_decimal_class (32 , uint32_t , double );
245255 sigma_decimal_class (64 , uint64_t , long double );
246- sigma_decimal_class (128 , uint128_t , long double );
256+ #if sigma_has_bid128
257+ sigma_decimal_class (128 , uint128_t , long double );
258+ #endif
247259
248260 // operator combinations
249261 #define sigma_external_operators (_bit_size_ ) \
@@ -254,7 +266,10 @@ namespace math {
254266 sigma_comparison_operator (uint##_bit_size_##_t, <=, __bid##_bit_size_##_quiet_less_equal); sigma_comparison_operator(uint##_bit_size_##_t, >=, __bid##_bit_size_##_quiet_greater_equal);
255267
256268 // operator instatiations for various bit sizes
257- sigma_external_operators (32 ); sigma_external_operators(64 ); sigma_external_operators(128 );
269+ sigma_external_operators (32 ); sigma_external_operators(64 );
270+ #if sigma_has_bid128
271+ sigma_external_operators (128 );
272+ #endif
258273 #undef sigma_external_operators
259274 #undef sigma_decimal_class
260275 #undef sigma_comparison_operator
@@ -269,8 +284,10 @@ namespace math {
269284 namespace literals {
270285 sigma_decimal_literal (uint32_t , _dec32);
271286 sigma_decimal_literal (uint64_t , _dec64);
272- sigma_decimal_literal (uint128_t , _dec128);
273287 sigma_decimal_literal (uint64_t , _dec);
288+ #if sigma_has_bid128
289+ sigma_decimal_literal (uint128_t , _dec128);
290+ #endif
274291 }
275292 #undef sigma_decimal_literal
276293 // begin utilities:
@@ -304,7 +321,9 @@ namespace math {
304321namespace math {
305322 sigma_stream_op (uint32_t );
306323 sigma_stream_op (uint64_t );
307- sigma_stream_op (BID_UINT128);
324+ #if sigma_has_bid128
325+ sigma_stream_op (BID_UINT128);
326+ #endif
308327}
309328#undef sigma_stream_op
310329
@@ -349,7 +368,10 @@ namespace math {
349368 sigma_unary_op (N, cbrt) sigma_unary_op(N, atanh) sigma_unary_op(N, asinh) sigma_unary_op(N, asin) \
350369 sigma_unary_op (N, acosh) sigma_unary_op(N, acos) sigma_unary_op(N, sqrt)
351370
352- sigma_op (32 ); sigma_op(64 ); sigma_op(128 );
371+ sigma_op (32 ); sigma_op(64 );
372+ #if sigma_has_bid128
373+ sigma_op (128 );
374+ #endif
353375
354376 #undef sigma__op
355377 #undef sigma_unary_op
@@ -417,6 +439,7 @@ namespace math {
417439 inline static const decimal_t cube_root_2 = static_cast <decimal_t >(" 1.259921049894873" );
418440 inline static const decimal_t cube_root_3 = static_cast <decimal_t >(" 1.442249570307408" );
419441 };
442+ #if sigma_has_bid128
420443 template <> struct constants <BID_UINT128> { // 34 digit precision
421444 using decimal_t = typename math::decimal_t <BID_UINT128>;
422445 inline static const decimal_t nan = static_cast <decimal_t >(" nan" );
@@ -445,5 +468,6 @@ namespace math {
445468 inline static const decimal_t quarter_pi = static_cast <decimal_t >(" 0.7853981633974483096156608458198757" );
446469 inline static const decimal_t cube_root_2 = static_cast <decimal_t >(" 1.2599210498948731647672106072782284" );
447470 inline static const decimal_t cube_root_3 = static_cast <decimal_t >(" 1.4422495703074083823216383107801096" );
448- };
471+ };
472+ #endif
449473}
0 commit comments