New o3tl::temporary to simplify calls of std::modf
...that ignore the out-parameter integral part Change-Id: I05f07c1a8909023232f8aecf75ea5541d4eb81ca Reviewed-on: https://gerrit.libreoffice.org/54474 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <math.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include <o3tl/temporary.hxx>
|
||||
#include <rtl/math.hxx>
|
||||
#include <codegen.hxx>
|
||||
#include <parser.hxx>
|
||||
@@ -152,8 +153,7 @@ void SbiExprNode::ConvertToIntConstIfPossible()
|
||||
{
|
||||
if( eType >= SbxINTEGER && eType <= SbxDOUBLE )
|
||||
{
|
||||
double n;
|
||||
if( nVal >= SbxMININT && nVal <= SbxMAXINT && modf( nVal, &n ) == 0 )
|
||||
if( nVal >= SbxMININT && nVal <= SbxMAXINT && modf( nVal, &o3tl::temporary(double()) ) == 0 )
|
||||
{
|
||||
eType = SbxINTEGER;
|
||||
}
|
||||
@@ -220,9 +220,8 @@ void SbiExprNode::FoldConstants(SbiParser* pParser)
|
||||
// Potentially convolve in INTEGER (because of better opcode)?
|
||||
if( eType == SbxSINGLE || eType == SbxDOUBLE )
|
||||
{
|
||||
double x;
|
||||
if( nVal >= SbxMINLNG && nVal <= SbxMAXLNG
|
||||
&& !modf( nVal, &x ) )
|
||||
&& !modf( nVal, &o3tl::temporary(double()) ) )
|
||||
eType = SbxLONG;
|
||||
}
|
||||
if( eType == SbxLONG && nVal >= SbxMININT && nVal <= SbxMAXINT )
|
||||
@@ -463,9 +462,8 @@ void SbiExprNode::FoldConstantsUnaryNode(SbiParser* pParser)
|
||||
// Potentially convolve in INTEGER (because of better opcode)?
|
||||
if( eType == SbxSINGLE || eType == SbxDOUBLE )
|
||||
{
|
||||
double x;
|
||||
if( nVal >= SbxMINLNG && nVal <= SbxMAXLNG
|
||||
&& !modf( nVal, &x ) )
|
||||
&& !modf( nVal, &o3tl::temporary(double()) ) )
|
||||
eType = SbxLONG;
|
||||
}
|
||||
if( eType == SbxLONG && nVal >= SbxMININT && nVal <= SbxMAXINT )
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include <svl/zforlist.hxx>
|
||||
#include <tools/urlobj.hxx>
|
||||
#include <tools/fract.hxx>
|
||||
#include <o3tl/temporary.hxx>
|
||||
#include <osl/file.hxx>
|
||||
#include <vcl/jobset.hxx>
|
||||
#include <sbobjmod.hxx>
|
||||
@@ -2354,8 +2355,7 @@ void SbRtl_FormatDateTime(StarBASIC *, SbxArray & rPar, bool)
|
||||
// ShortTime: Display a time using the 24-hour format (hh:mm).
|
||||
// 11:24
|
||||
case 4:
|
||||
double n;
|
||||
double dTime = modf( dDate, &n );
|
||||
double dTime = modf( dDate, &o3tl::temporary(double()) );
|
||||
pSbxVar->PutDate( dTime );
|
||||
if( nNamedFormat == 3 )
|
||||
{
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
||||
/*
|
||||
* 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 <sal/config.h>
|
||||
|
||||
namespace o3tl
|
||||
{
|
||||
// Cast an rvalue to an lvalue. Can be useful if a function parameter is a pointer/reference to T,
|
||||
// and some call site doesn't need the value beyond the call itself (e.g., in a call like
|
||||
// std::modf(x, &o3tl::temporary(double())) to obtain the fractional part of x, ignoring the
|
||||
// integral part).
|
||||
template <typename T> constexpr T& temporary(T&& x) { return x; }
|
||||
template <typename T> constexpr T& temporary(T&) = delete;
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|
||||
@@ -0,0 +1,16 @@
|
||||
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; fill-column: 100 -*-
|
||||
#
|
||||
# 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/.
|
||||
#
|
||||
|
||||
$(eval $(call gb_CompilerTest_CompilerTest,o3tl_temporary))
|
||||
|
||||
$(eval $(call gb_CompilerTest_add_exception_objects,o3tl_temporary, \
|
||||
o3tl/qa/compile-temporary \
|
||||
))
|
||||
|
||||
# vim: set noet sw=4 ts=4:
|
||||
@@ -23,6 +23,7 @@ $(eval $(call gb_Module_add_targets,o3tl,\
|
||||
|
||||
$(eval $(call gb_Module_add_check_targets,o3tl,\
|
||||
CppunitTest_o3tl_tests \
|
||||
$(if $(COM_IS_CLANG),CompilerTest_o3tl_temporary) \
|
||||
))
|
||||
|
||||
# vim: set noet sw=4:
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
||||
/*
|
||||
* 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 <sal/config.h>
|
||||
|
||||
#include <o3tl/temporary.hxx>
|
||||
|
||||
void f(int*);
|
||||
|
||||
int g();
|
||||
|
||||
void h(int n)
|
||||
{
|
||||
f(&o3tl::temporary(int()));
|
||||
f(&o3tl::temporary(g()));
|
||||
f(&o3tl::temporary(n)); // expected-error {{}} expected-note@o3tl/temporary.hxx:* 0+ {{}}
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "xmlControlProperty.hxx"
|
||||
|
||||
#include <o3tl/temporary.hxx>
|
||||
#include <rtl/strbuf.hxx>
|
||||
#include <sax/tools/converter.hxx>
|
||||
#include "xmlfilter.hxx"
|
||||
@@ -272,8 +273,7 @@ Any OXMLControlProperty::convertString(const css::uno::Type& _rExpectedType, con
|
||||
{
|
||||
case TYPE_DATE:
|
||||
{
|
||||
double dummy;
|
||||
OSL_ENSURE(std::modf(nValue, &dummy) == 0,
|
||||
OSL_ENSURE(std::modf(nValue, &o3tl::temporary(double())) == 0,
|
||||
"OPropertyImport::convertString: a Date value with a fractional part?");
|
||||
(void)dummy;
|
||||
aReturn <<= implGetDate(nValue);
|
||||
|
||||
+2
-1
@@ -22,6 +22,7 @@
|
||||
#include <cmath>
|
||||
|
||||
#include <sal/types.h>
|
||||
#include <o3tl/temporary.hxx>
|
||||
#include <osl/thread.h>
|
||||
#include <osl/thread.hxx>
|
||||
#include <osl/time.h>
|
||||
@@ -85,7 +86,7 @@ static double data(RandomData_Impl *pImpl)
|
||||
(static_cast<double>(pImpl->m_nY) / 30269.0) +
|
||||
(static_cast<double>(pImpl->m_nZ) / 30307.0) );
|
||||
|
||||
return std::modf(random, &random);
|
||||
return std::modf(random, &o3tl::temporary(double()));
|
||||
}
|
||||
|
||||
static bool initPool(RandomPool_Impl *pImpl)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <document.hxx>
|
||||
#include <generalfunction.hxx>
|
||||
|
||||
#include <o3tl/temporary.hxx>
|
||||
#include <oox/export/utils.hxx>
|
||||
#include <oox/token/namespaces.hxx>
|
||||
#include <sax/tools/converter.hxx>
|
||||
@@ -263,7 +264,6 @@ void XclExpXmlPivotCaches::SavePivotCacheXml( XclExpXmlStream& rStrm, const Entr
|
||||
double fMin = std::numeric_limits<double>::infinity(), fMax = -std::numeric_limits<double>::infinity();
|
||||
bool isValueInteger = true;
|
||||
bool isContainsDate = rCache.IsDateDimension(i);
|
||||
double intpart;
|
||||
for (; it != itEnd; ++it)
|
||||
{
|
||||
ScDPItemData::Type eType = it->GetType();
|
||||
@@ -275,7 +275,7 @@ void XclExpXmlPivotCaches::SavePivotCacheXml( XclExpXmlStream& rStrm, const Entr
|
||||
fMax = std::max(fMax, fVal);
|
||||
|
||||
// Check if all values are integers
|
||||
if (isValueInteger && (modf(fVal, &intpart) != 0.0))
|
||||
if (isValueInteger && (modf(fVal, &o3tl::temporary(double())) != 0.0))
|
||||
{
|
||||
isValueInteger = false;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "analysis.hxx"
|
||||
#include "analysishelper.hxx"
|
||||
#include <o3tl/temporary.hxx>
|
||||
#include <rtl/math.hxx>
|
||||
|
||||
using namespace sca::analysis;
|
||||
@@ -366,8 +367,7 @@ double SAL_CALL AnalysisAddIn::getTbillprice( const css::uno::Reference< css::be
|
||||
|
||||
double fFraction = GetYearFrac( xOpt, nSettle, nMat, 0 ); // method: USA 30/360
|
||||
|
||||
double fDummy;
|
||||
if( modf( fFraction, &fDummy ) == 0.0 )
|
||||
if( modf( fFraction, &o3tl::temporary(double()) ) == 0.0 )
|
||||
throw css::lang::IllegalArgumentException();
|
||||
|
||||
double fRet = 100.0 * ( 1.0 - fDisc * fFraction );
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <o3tl/temporary.hxx>
|
||||
#include <osl/diagnose.h>
|
||||
#include <basegfx/matrix/b2dhommatrix.hxx>
|
||||
#include <basegfx/point/b2dpoint.hxx>
|
||||
@@ -102,8 +103,7 @@ SnakeWipe::SnakeWipe( sal_Int32 nElements, bool diagonal, bool flipOnYAxis )
|
||||
res.append(poly);
|
||||
}
|
||||
const double a = (M_SQRT1_2 / m_sqrtElements);
|
||||
double dummy;
|
||||
const double d = std::modf(sqrtArea2, &dummy);
|
||||
const double d = std::modf(sqrtArea2, &o3tl::temporary(double()));
|
||||
const double len = (t * M_SQRT2 * d);
|
||||
const double height = ::basegfx::pruneScaleValue( M_SQRT1_2 / m_sqrtElements );
|
||||
poly.clear();
|
||||
@@ -147,8 +147,7 @@ SnakeWipe::SnakeWipe( sal_Int32 nElements, bool diagonal, bool flipOnYAxis )
|
||||
res.append(poly);
|
||||
}
|
||||
const double a = (M_SQRT1_2 / m_sqrtElements);
|
||||
double dummy;
|
||||
const double d = std::modf(sqrtArea2, &dummy);
|
||||
const double d = std::modf(sqrtArea2, &o3tl::temporary(double()));
|
||||
const double len = ((1.0 - t) * M_SQRT2 * d);
|
||||
const double height = ::basegfx::pruneScaleValue( M_SQRT1_2 / m_sqrtElements );
|
||||
poly.clear();
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include <editeng/unolingu.hxx>
|
||||
#include <expfld.hxx>
|
||||
#include <hintids.hxx>
|
||||
#include <o3tl/temporary.hxx>
|
||||
#include <osl/diagnose.hxx>
|
||||
#include <rtl/math.hxx>
|
||||
#include <shellres.hxx>
|
||||
@@ -1195,8 +1196,8 @@ SwSbxValue SwCalc::Prim()
|
||||
GetToken();
|
||||
double right = Prim().GetDouble();
|
||||
|
||||
double fraction, integer;
|
||||
fraction = modf( right, &integer );
|
||||
double fraction;
|
||||
fraction = modf( right, &o3tl::temporary(double()) );
|
||||
if( ( dleft < 0.0 && 0.0 != fraction ) ||
|
||||
( 0.0 == dleft && right < 0.0 ) )
|
||||
{
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <sal/config.h>
|
||||
|
||||
#include <o3tl/any.hxx>
|
||||
#include <o3tl/temporary.hxx>
|
||||
#include <tools/datetime.hxx>
|
||||
#include <svl/zforlist.hxx>
|
||||
#include <com/sun/star/util/DateTime.hpp>
|
||||
@@ -150,8 +151,7 @@ Date SwDateTimeField::GetDate() const
|
||||
|
||||
tools::Time SwDateTimeField::GetTime() const
|
||||
{
|
||||
double fDummy;
|
||||
double fFract = modf(GetValue(), &fDummy);
|
||||
double fFract = modf(GetValue(), &o3tl::temporary(double()));
|
||||
DateTime aDT( DateTime::EMPTY );
|
||||
aDT.AddTime(fFract);
|
||||
return static_cast<tools::Time>(aDT);
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
#include <com/sun/star/text/XTextColumns.hpp>
|
||||
#include <com/sun/star/awt/CharSet.hpp>
|
||||
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
||||
|
||||
#include <o3tl/temporary.hxx>
|
||||
#include <oox/mathml/import.hxx>
|
||||
#include <rtl/uri.hxx>
|
||||
#include "GraphicHelpers.hxx"
|
||||
@@ -4587,8 +4587,7 @@ static util::DateTime lcl_dateTimeFromSerial(const double& dSerial)
|
||||
DateTime d(Date(30, 12, 1899));
|
||||
d.AddDays( static_cast<sal_Int32>(dSerial) );
|
||||
|
||||
double dummy;
|
||||
double frac = std::modf(dSerial, &dummy);
|
||||
double frac = std::modf(dSerial, &o3tl::temporary(double()));
|
||||
sal_uInt32 seconds = frac * secondsPerDay;
|
||||
|
||||
util::DateTime date;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <xmloff/xmlimp.hxx>
|
||||
#include <xmloff/xmluconv.hxx>
|
||||
#include <xmloff/nmspmap.hxx>
|
||||
#include <o3tl/temporary.hxx>
|
||||
#include <osl/diagnose.h>
|
||||
#include <comphelper/extract.hxx>
|
||||
#include "callbacks.hxx"
|
||||
@@ -186,9 +187,7 @@ Any PropertyConversion::convertString( const css::uno::Type& _rExpectedType,
|
||||
{
|
||||
case TYPE_DATE:
|
||||
{
|
||||
double dummy;
|
||||
(void) dummy; // avoid warning C4101 with some over-eager MSVC
|
||||
OSL_ENSURE(std::modf(nValue, &dummy) == 0,
|
||||
OSL_ENSURE(std::modf(nValue, &o3tl::temporary(double())) == 0,
|
||||
"PropertyConversion::convertString: a Date value with a fractional part?");
|
||||
aReturn <<= lcl_getDate(nValue);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user