#include "support/docstream.h"
#include "support/lstrings.h"
+#include "support/lyxlib.h"
#include <sstream>
#include <iomanip>
double const text_width_in = text_width / (zoom * dpi);
double const result = zoom * dpi * inInch(text_width_in, em_width_in);
- return static_cast<int>(result + ((result >= 0) ? 0.5 : -0.5));
+ return support::iround(result);
}
double const text_width_in = 210.0 / 2.54; // assume A4
double const em_width_in = 10.0 / 72.27;
double result = 72.0 * inInch(text_width_in, em_width_in);
- return static_cast<int>(result + 0.5);
+ return support::iround(result);
}
if (!params().scale.empty() && !float_equal(scl, 0.0, 0.05)) {
if (!float_equal(scl, 100.0, 0.05))
options << " scale=\""
- << static_cast<int>( (scl) + 0.5 )
+ << support::iround(scl)
<< "\" ";
} else {
if (!params().width.zero()) {
#include "support/debug.h"
#include "support/lstrings.h"
+#include "support/lyxlib.h"
#include "support/textutils.h"
}
int const em = mathed_font_em(mi.base.font);
if (isBinaryOp(char_))
- dim.wid += static_cast<int>(0.5*em+0.5);
+ dim.wid += support::iround(0.5 * em);
else if (char_ == '\'')
- dim.wid += static_cast<int>(0.1667*em+0.5);
+ dim.wid += support::iround(0.1667 * em);
#else
whichFont(font_, code_, mi);
dim = theFontMetrics(font_).dimension(char_);
//lyxerr << "drawing '" << char_ << "' font: " << pi.base.fontname << std::endl;
int const em = mathed_font_em(pi.base.font);
if (isBinaryOp(char_))
- x += static_cast<int>(0.25*em+0.5);
+ x += support::iround(0.25 * em);
else if (char_ == '\'')
- x += static_cast<int>(0.0833*em+0.5);
+ x += support::iround(0.0833 * em);
#if 1
if (char_ == '=' && has_math_fonts) {
FontSetChanger dummy(pi.base, "cmr");
#include "support/debug.h"
#include "support/docstream.h"
+#include "support/lyxlib.h"
#include "support/textutils.h"
#include <boost/scoped_ptr.hpp>
}
// seperate things a bit
if (isRelOp())
- dim.wid += static_cast<int>(0.5 * em + 0.5);
+ dim.wid += support::iround(0.5 * em);
else
- dim.wid += static_cast<int>(0.1667 * em + 0.5);
+ dim.wid += support::iround(0.1667 * em);
scriptable_ = false;
if (mi.base.style == LM_ST_DISPLAY)
std::string const font = italic_upcase_greek ? "cmm" : sym_->inset;
int const em = mathed_font_em(pi.base.font);
if (isRelOp())
- x += static_cast<int>(0.25*em+0.5);
+ x += support::iround(0.25 * em);
else
- x += static_cast<int>(0.0833*em+0.5);
+ x += support::iround(0.0833 * em);
FontSetChanger dummy(pi.base, from_ascii(font));
pi.draw(x, y - h_, sym_->draw);
#include "support/convert.h"
#include "support/debug.h"
+#include "support/lyxlib.h"
#include "support/qstring_helpers.h"
#include "support/lassert.h"
#include <QString>
-#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
}
-#ifdef _MSC_VER
-// Replacement for C99 function lround()
-double round(double x)
-{
- if (x < 0)
- return ceil(x - 0.5);
- else
- return floor(x + 0.5);
-}
-#endif
-
-
std::string formatFPNumber(double x)
{
// Need manual tweaking, QString::number(x, 'f', 16) does not work either
// Prevent outputs of 23.4200000000000017 but output small numbers
// with at least 6 significant digits.
double const logarithm = log10(fabs(x));
- os << std::setprecision(max(6 - static_cast<int>(round(logarithm)), 0)) << x;
+ os << std::setprecision(max(6 - iround(logarithm), 0)) << x;
string result = os.str();
if (result.find('.') != string::npos) {
result = rtrim(result, "0");
#ifndef LYX_LIB_H
#define LYX_LIB_H
+// always include <math.h> (also with MSVC), to avoid compiler specific side effects
+#include <math.h>
+
+#ifdef _MSC_VER
+/// Replacement for C99 round()
+inline double round(double x)
+{
+ if (x < 0)
+ return ceil(x - 0.5);
+ else
+ return floor(x + 0.5);
+}
+#endif
+
namespace lyx {
namespace support {
return (number - error <= var && var <= number + error);
}
+/// round \p x to nearest integer
+inline int iround(double x)
+{
+ return static_cast<int>(round(x));
+}
+
} // namespace support
} // namespace lyx