github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/cxx/osmpf.cc (about)

     1  /* operator<< -- mpf formatted output to an ostream.
     2  
     3  Copyright 2001, 2002 Free Software Foundation, Inc.
     4  
     5  This file is part of the GNU MP Library.
     6  
     7  The GNU MP Library is free software; you can redistribute it and/or modify
     8  it under the terms of either:
     9  
    10    * the GNU Lesser General Public License as published by the Free
    11      Software Foundation; either version 3 of the License, or (at your
    12      option) any later version.
    13  
    14  or
    15  
    16    * the GNU General Public License as published by the Free Software
    17      Foundation; either version 2 of the License, or (at your option) any
    18      later version.
    19  
    20  or both in parallel, as here.
    21  
    22  The GNU MP Library is distributed in the hope that it will be useful, but
    23  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    24  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    25  for more details.
    26  
    27  You should have received copies of the GNU General Public License and the
    28  GNU Lesser General Public License along with the GNU MP Library.  If not,
    29  see https://www.gnu.org/licenses/.  */
    30  
    31  #include <clocale>
    32  #include <iostream>
    33  #include <stdarg.h>    /* for va_list and hence doprnt_funs_t */
    34  #include <string.h>
    35  
    36  #include "gmp.h"
    37  #include "gmp-impl.h"
    38  
    39  using namespace std;
    40  
    41  
    42  /* The gmp_asprintf support routines never give an error, so
    43     __gmp_doprnt_mpf shouldn't fail and it's return can just be checked with
    44     an ASSERT.  */
    45  
    46  ostream&
    47  operator<< (ostream &o, mpf_srcptr f)
    48  {
    49    struct doprnt_params_t  param;
    50    struct gmp_asprintf_t   d;
    51    char  *result;
    52    int   ret;
    53  
    54    __gmp_doprnt_params_from_ios (&param, o);
    55  
    56  #if HAVE_STD__LOCALE
    57    char  point[2];
    58    point[0] = use_facet< numpunct<char> >(o.getloc()).decimal_point();
    59    point[1] = '\0';
    60  #else
    61    const char *point = GMP_DECIMAL_POINT;
    62  #endif
    63  
    64    GMP_ASPRINTF_T_INIT (d, &result);
    65    ret = __gmp_doprnt_mpf (&__gmp_asprintf_funs_noformat, &d, &param, point, f);
    66    ASSERT (ret != -1);
    67    __gmp_asprintf_final (&d);
    68  
    69    gmp_allocated_string  t (result);
    70    return o.write (t.str, t.len);
    71  }