github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/common/math/softfloat.cpp (about)

     1  // Copyright (C) 2018 go-nebulas authors
     2  //
     3  // This file is part of the go-nebulas library.
     4  //
     5  // the go-nebulas library is free software: you can redistribute it and/or
     6  // modify
     7  // it under the terms of the GNU General Public License as published by
     8  // the Free Software Foundation, either version 3 of the License, or
     9  // (at your option) any later version.
    10  //
    11  // the go-nebulas library is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU General Public License
    17  // along with the go-nebulas library.  If not, see
    18  // <http://www.gnu.org/licenses/>.
    19  //
    20  
    21  #include "common/math/softfloat.hpp"
    22  #include <glog/logging.h>
    23  #include <sstream>
    24  
    25  /*----------------------------------------------------------------------------
    26  | Software floating-point exception flags.
    27  | extern THREAD_LOCAL uint_fast8_t softfloat_exceptionFlags;
    28  | enum {
    29  |     softfloat_flag_inexact   =  1,
    30  |     softfloat_flag_underflow =  2,
    31  |     softfloat_flag_overflow  =  4,
    32  |     softfloat_flag_infinite  =  8,
    33  |     softfloat_flag_invalid   = 16
    34  | };
    35  *----------------------------------------------------------------------------*/
    36  
    37  void softfloat_raiseFlags(uint_fast8_t exception_flag) {
    38    std::stringstream ss;
    39    ss << "raise flag: " << static_cast<int>(exception_flag)
    40       << ", softfloat exception: ";
    41    uint_fast8_t flag = 0x10;
    42    while (flag) {
    43      switch (flag & exception_flag) {
    44      case softfloat_flag_inexact:
    45        ss << "inexact ";
    46        break;
    47      case softfloat_flag_underflow:
    48        ss << "underflow ";
    49        break;
    50      case softfloat_flag_overflow:
    51        ss << "overflow ";
    52        break;
    53      case softfloat_flag_infinite:
    54        ss << "infinite ";
    55        break;
    56      case softfloat_flag_invalid:
    57        ss << "invalid ";
    58        break;
    59      default:
    60        break;
    61      }
    62      flag >>= 1;
    63    }
    64    LOG(INFO) << ss.str();
    65  
    66    // ignore softfloat exception
    67    // throw std::runtime_error("softfloat exception");
    68  }