@@ -2404,6 +2404,8 @@ Dragon4_PrintFloat64(char *buffer, npy_uint32 bufferSize, npy_float64 value,
2404
2404
}
2405
2405
}
2406
2406
2407
+ #if !(defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_BE ) || \
2408
+ defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_LE ))
2407
2409
static npy_uint32
2408
2410
Dragon4_PrintFloat128 (char * buffer , npy_uint32 bufferSize , FloatVal128 value ,
2409
2411
npy_bool scientific , DigitMode digit_mode ,
@@ -2499,6 +2501,7 @@ Dragon4_PrintFloat128(char *buffer, npy_uint32 bufferSize, FloatVal128 value,
2499
2501
digits_left , digits_right );
2500
2502
}
2501
2503
}
2504
+ #endif /* DOUBLE_DOUBLE */
2502
2505
2503
2506
PyObject *
2504
2507
Dragon4_Positional_AnySize (void * val , size_t size , DigitMode digit_mode ,
@@ -2510,16 +2513,22 @@ Dragon4_Positional_AnySize(void *val, size_t size, DigitMode digit_mode,
2510
2513
* 16384 should be enough to uniquely print any float128, which goes up
2511
2514
* to about 10^4932 */
2512
2515
static char repr [16384 ];
2516
+ #if !(defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_BE ) || \
2517
+ defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_LE ))
2513
2518
FloatVal128 val128 ;
2519
+ #ifdef NPY_FLOAT128
2520
+ FloatUnion128 buf128 ;
2521
+ #endif
2522
+ #else /* DOUBLE_DOUBLE */
2523
+ PyObject * out , * ret ;
2524
+ #endif /* DOUBLE_DOUBLE */
2525
+
2514
2526
#ifdef NPY_FLOAT80
2515
2527
FloatUnion80 buf80 ;;
2516
2528
#endif
2517
2529
#ifdef NPY_FLOAT96
2518
2530
FloatUnion96 buf96 ;
2519
2531
#endif
2520
- #ifdef NPY_FLOAT128
2521
- FloatUnion128 buf128 ;
2522
- #endif
2523
2532
2524
2533
switch (size ) {
2525
2534
case 2 :
@@ -2559,14 +2568,29 @@ Dragon4_Positional_AnySize(void *val, size_t size, DigitMode digit_mode,
2559
2568
#endif
2560
2569
#ifdef NPY_FLOAT128
2561
2570
case 16 :
2571
+ /* Numpy 1.14 does not support the DOUBLE_DOUBLE format properly */
2572
+ #if defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_BE ) || \
2573
+ defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_LE )
2574
+ PyOS_snprintf (repr , sizeof (repr ), "%.*Lf" , precision ,
2575
+ * (npy_float128 * )val );
2576
+ out = PyUString_FromString (repr );
2577
+ if (out == NULL ) {
2578
+ return out ;
2579
+ }
2580
+ /* strip trailing zeros to roughly emulate normal behavior */
2581
+ ret = PyObject_CallMethod (out , "rstrip" , "s" , "0" );
2582
+ Py_DECREF (out );
2583
+ return ret ;
2584
+ #else
2562
2585
buf128 .floatingPoint = * (npy_float128 * )val ;
2563
2586
val128 .integer [0 ] = buf128 .integer .a ;
2564
2587
val128 .integer [1 ] = buf128 .integer .b ;
2565
2588
Dragon4_PrintFloat128 (repr , sizeof (repr ), val128 ,
2566
2589
0 , digit_mode , cutoff_mode , precision ,
2567
2590
sign , trim , pad_left , pad_right , -1 );
2591
+ #endif /* DOUBLE_DOUBLE */
2568
2592
break ;
2569
- #endif
2593
+ #endif /* NPY_FLOAT128 */
2570
2594
default :
2571
2595
PyErr_Format (PyExc_ValueError , "unexpected itemsize %zu" , size );
2572
2596
return NULL ;
@@ -2623,16 +2647,20 @@ Dragon4_Scientific_AnySize(void *val, size_t size, DigitMode digit_mode,
2623
2647
{
2624
2648
/* use a very large buffer in case anyone tries to output a large precision */
2625
2649
static char repr [4096 ];
2650
+ #if !(defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_BE ) || \
2651
+ defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_LE ))
2626
2652
FloatVal128 val128 ;
2653
+ #ifdef NPY_FLOAT128
2654
+ FloatUnion128 buf128 ;
2655
+ #endif
2656
+ #endif /* DOUBLE_DOUBLE */
2657
+
2627
2658
#ifdef NPY_FLOAT80
2628
2659
FloatUnion80 buf80 ;;
2629
2660
#endif
2630
2661
#ifdef NPY_FLOAT96
2631
2662
FloatUnion96 buf96 ;
2632
2663
#endif
2633
- #ifdef NPY_FLOAT128
2634
- FloatUnion128 buf128 ;
2635
- #endif
2636
2664
2637
2665
/* dummy, is ignored in scientific mode */
2638
2666
CutoffMode cutoff_mode = CutoffMode_TotalLength ;
@@ -2675,14 +2703,21 @@ Dragon4_Scientific_AnySize(void *val, size_t size, DigitMode digit_mode,
2675
2703
#endif
2676
2704
#ifdef NPY_FLOAT128
2677
2705
case 16 :
2706
+ /* Numpy 1.14 does not support the DOUBLE_DOUBLE format properly */
2707
+ #if defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_BE ) || \
2708
+ defined(HAVE_LDOUBLE_DOUBLE_DOUBLE_LE )
2709
+ PyOS_snprintf (repr , sizeof (repr ), "%.*Le" , precision ,
2710
+ * (npy_float128 * )val );
2711
+ #else
2678
2712
buf128 .floatingPoint = * (npy_float128 * )val ;
2679
2713
val128 .integer [0 ] = buf128 .integer .a ;
2680
2714
val128 .integer [1 ] = buf128 .integer .b ;
2681
2715
Dragon4_PrintFloat128 (repr , sizeof (repr ), val128 ,
2682
2716
1 , digit_mode , cutoff_mode , precision , sign ,
2683
2717
trim , pad_left , -1 , exp_digits );
2718
+ #endif /* DOUBLE_DOUBLE */
2684
2719
break ;
2685
- #endif
2720
+ #endif /* NPY_FLOAT128 */
2686
2721
default :
2687
2722
PyErr_Format (PyExc_ValueError , "unexpected itemsize %zu" , size );
2688
2723
return NULL ;
0 commit comments