Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  utils.cxx   Sprache: C

 
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */


#include "utils.hxx"

#include <cassert>
#include <cfloat>
#include <limits>
#include <sstream>

namespace sc
{
namespace opencl
{
namespace
{
#ifdef SAL_LOG_INFO
class outputstream_num_put : public std::num_put<char>
{
protected:
    virtual iter_type do_put(iter_type s, std::ios_base&, char_type, double v) const override
    {
        std::string str = preciseFloat(v);
        return std::copy(str.begin(), str.end(), s);
    }
    virtual iter_type do_put(iter_type, std::ios_base&, char_type, long doubleconst override
    {
        abort(); // we do not use these
    }
    using std::num_put<char>::do_put;
};
#endif
// namespace

outputstream::outputstream()
{
    precision(DECIMAL_DIG);
    setf(std::ios::showpoint);
#ifdef SAL_LOG_INFO
    // Calling precision() makes the output have trailing insignificant zeroes, which
    // makes reading the source annoying. So override this stream's floating output
    // handling to force usage of our preciseFloat(), which has a saner output.
    imbue(std::locale(std::locale("C"), new outputstream_num_put));
#endif
}

#undef stringstream
std::string preciseFloat(double f)
{
    std::stringstream stream;
    stream.precision(std::numeric_limits<double>::digits10 + 1);
    stream.setf(std::ios::showpoint);
    stream << f;
    std::string str = stream.str();
    size_t end = str.find('e');
    if (end == std::string::npos)
        end = str.size();
    for (size_t pos = end - 1; pos > 0; --pos)
    {
        if (str[pos] != '0')
        {
            if (str[pos] == '.')
            {
                ++pos;
                if (pos == end) // 10. without trailing 0
                {
                    return str + '0';
                }
            }
            ++pos;
            assert(pos <= end);
            str.resize(std::copy(str.begin() + end, str.end(), str.begin() + pos) - str.begin());
            return str;
        }
    }
    abort();
}
}
// namespace

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Messung V0.5
C=93 H=95 G=93

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge