xref: /netbsd/external/lgpl3/mpfr/dist/src/print_raw.c (revision 606004a0)
1 /* mpfr_print_mant_binary -- print the internal binary representation
2    of a significand of floating-point number (for the tests and
3    debugging purpose)
4 
5 Copyright 1999-2023 Free Software Foundation, Inc.
6 Contributed by the AriC and Caramba projects, INRIA.
7 
8 This file is part of the GNU MPFR Library.
9 
10 The GNU MPFR Library is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or (at your
13 option) any later version.
14 
15 The GNU MPFR Library is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
18 License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
22 https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
24 
25 #include "mpfr-impl.h"
26 
27 void
mpfr_print_mant_binary(const char * str,const mp_limb_t * p,mpfr_prec_t r)28 mpfr_print_mant_binary (const char *str, const mp_limb_t *p, mpfr_prec_t r)
29 {
30   int i;
31   mpfr_prec_t count = 0;
32   mp_size_t n = MPFR_PREC2LIMBS (r);
33 
34   printf ("%s ", str);
35   for (n-- ; n >= 0 ; n--)
36     {
37       for (i = GMP_NUMB_BITS - 1 ; i >=0 ; i--)
38         {
39           putchar ((p[n] & (MPFR_LIMB_ONE << i)) ? '1' : '0');
40           if (++count == r)
41             putchar ('[');
42         }
43       putchar ('.');
44     }
45   if (count >= r)
46     putchar (']');
47   putchar ('\n');
48 }
49