Bug 835542 - Implement mozilla::Abs. r=Ms2ger

--HG--
extra : rebase_source : a3e62ff76365d27cc4cb10e4fee942ddb8b10b79
This commit is contained in:
Jeff Walden 2013-02-15 19:55:36 -08:00
parent 56bb38cf34
commit 72eca3f9c1
32 changed files with 215 additions and 142 deletions

View File

@ -83,6 +83,7 @@
#include "mozilla/gfx/PathHelpers.h"
#include "mozilla/ipc/DocumentRendererParent.h"
#include "mozilla/ipc/PDocumentRendererParent.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/Preferences.h"
#include "mozilla/Telemetry.h"
#include "mozilla/unused.h"
@ -94,8 +95,6 @@
#include "mozilla/dom/HTMLImageElement.h"
#include "nsHTMLVideoElement.h"
#include "mozilla/dom/CanvasRenderingContext2DBinding.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
#ifdef XP_WIN
#include "gfxWindowsPlatform.h"
@ -3689,8 +3688,8 @@ CanvasRenderingContext2D::CreateImageData(JSContext* cx, double sw,
int32_t wi = JS_DoubleToInt32(sw);
int32_t hi = JS_DoubleToInt32(sh);
uint32_t w = std::abs(wi);
uint32_t h = std::abs(hi);
uint32_t w = Abs(wi);
uint32_t h = Abs(hi);
return mozilla::dom::CreateImageData(cx, this, w, h, error);
}

View File

@ -4,6 +4,8 @@
* 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 "mozilla/Attributes.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/dom/TabParent.h"
#include "nsCOMPtr.h"
@ -93,12 +95,9 @@
#include "mozilla/Preferences.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/Attributes.h"
#include "sampler.h"
#include "nsIDOMClientRect.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
#ifdef XP_MACOSX
#import <ApplicationServices/ApplicationServices.h>
@ -2053,8 +2052,8 @@ nsEventStateManager::GenerateDragGesture(nsPresContext* aPresContext,
// fire drag gesture if mouse has moved enough
nsIntPoint pt = aEvent->refPoint + aEvent->widget->WidgetToScreenOffset();
if (std::abs(pt.x - mGestureDownPoint.x) > pixelThresholdX ||
std::abs(pt.y - mGestureDownPoint.y) > pixelThresholdY) {
if (Abs(pt.x - mGestureDownPoint.x) > pixelThresholdX ||
Abs(pt.y - mGestureDownPoint.y) > pixelThresholdY) {
if (mClickHoldContextMenu) {
// stop the click-hold before we fire off the drag gesture, in case
// it takes a long time
@ -2880,14 +2879,14 @@ nsEventStateManager::DoScrollText(nsIScrollableFrame* aScrollableFrame,
nsIntSize devPixelPageSize(pc->AppUnitsToDevPixels(pageSize.width),
pc->AppUnitsToDevPixels(pageSize.height));
if (!WheelPrefs::GetInstance()->IsOverOnePageScrollAllowedX(aEvent) &&
std::abs(actualDevPixelScrollAmount.x) > devPixelPageSize.width) {
Abs(actualDevPixelScrollAmount.x) > devPixelPageSize.width) {
actualDevPixelScrollAmount.x =
(actualDevPixelScrollAmount.x >= 0) ? devPixelPageSize.width :
-devPixelPageSize.width;
}
if (!WheelPrefs::GetInstance()->IsOverOnePageScrollAllowedY(aEvent) &&
std::abs(actualDevPixelScrollAmount.y) > devPixelPageSize.height) {
Abs(actualDevPixelScrollAmount.y) > devPixelPageSize.height) {
actualDevPixelScrollAmount.y =
(actualDevPixelScrollAmount.y >= 0) ? devPixelPageSize.height :
-devPixelPageSize.height;
@ -5579,8 +5578,8 @@ nsEventStateManager::WheelPrefs::ComputeActionFor(widget::WheelEvent* aEvent)
Init(index);
bool deltaXPreferred =
(std::abs(aEvent->deltaX) > std::abs(aEvent->deltaY) &&
std::abs(aEvent->deltaX) > std::abs(aEvent->deltaZ));
(Abs(aEvent->deltaX) > Abs(aEvent->deltaY) &&
Abs(aEvent->deltaX) > Abs(aEvent->deltaZ));
Action* actions = deltaXPreferred ? mOverriddenActionsX : mActions;
if (actions[index] == ACTION_NONE || actions[index] == ACTION_SCROLL) {
return actions[index];
@ -5614,7 +5613,7 @@ nsEventStateManager::WheelPrefs::IsOverOnePageScrollAllowedX(
{
Index index = GetIndexFor(aEvent);
Init(index);
return std::abs(mMultiplierX[index]) >=
return Abs(mMultiplierX[index]) >=
MIN_MULTIPLIER_VALUE_ALLOWING_OVER_ONE_PAGE_SCROLL;
}
@ -5624,6 +5623,6 @@ nsEventStateManager::WheelPrefs::IsOverOnePageScrollAllowedY(
{
Index index = GetIndexFor(aEvent);
Init(index);
return std::abs(mMultiplierY[index]) >=
return Abs(mMultiplierY[index]) >=
MIN_MULTIPLIER_VALUE_ALLOWING_OVER_ONE_PAGE_SCROLL;
}

View File

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsHTMLMediaElement.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/Util.h"
#include "base/basictypes.h"
@ -72,8 +73,6 @@
#include "ImageContainer.h"
#include "nsIPowerManagerService.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
#include <algorithm>
#ifdef MOZ_OGG
@ -3520,10 +3519,10 @@ static double ClampPlaybackRate(double aPlaybackRate)
if (aPlaybackRate == 0.0) {
return aPlaybackRate;
}
if (std::abs(aPlaybackRate) < MIN_PLAYBACKRATE) {
if (Abs(aPlaybackRate) < MIN_PLAYBACKRATE) {
return aPlaybackRate < 0 ? -MIN_PLAYBACKRATE : MIN_PLAYBACKRATE;
}
if (std::abs(aPlaybackRate) > MAX_PLAYBACKRATE) {
if (Abs(aPlaybackRate) > MAX_PLAYBACKRATE) {
return aPlaybackRate < 0 ? -MAX_PLAYBACKRATE : MAX_PLAYBACKRATE;
}
return aPlaybackRate;

View File

@ -5,6 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "MediaDecoder.h"
#include "mozilla/FloatingPoint.h"
#include "mozilla/MathAlgorithms.h"
#include <limits>
#include "nsNetUtil.h"
#include "AudioStream.h"
@ -20,10 +22,7 @@
#include "MediaResource.h"
#include "nsError.h"
#include "mozilla/Preferences.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
#include <algorithm>
#include <mozilla/FloatingPoint.h>
#ifdef MOZ_WMF
#include "WMFDecoder.h"
@ -595,11 +594,11 @@ nsresult MediaDecoder::Seek(double aTime)
NS_ENSURE_SUCCESS(res, NS_OK);
res = seekable.Start(range + 1, &rightBound);
NS_ENSURE_SUCCESS(res, NS_OK);
double distanceLeft = std::abs(leftBound - aTime);
double distanceRight = std::abs(rightBound - aTime);
double distanceLeft = Abs(leftBound - aTime);
double distanceRight = Abs(rightBound - aTime);
if (distanceLeft == distanceRight) {
distanceLeft = std::abs(leftBound - mCurrentTime);
distanceRight = std::abs(rightBound - mCurrentTime);
distanceLeft = Abs(leftBound - mCurrentTime);
distanceRight = Abs(rightBound - mCurrentTime);
}
aTime = (distanceLeft < distanceRight) ? leftBound : rightBound;
} else {

View File

@ -35,8 +35,7 @@
// For calculating max history entries and max cachable contentviewers
#include "nspr.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double), and std::log(double)
#include "mozilla/MathAlgorithms.h"
using namespace mozilla;
@ -1102,8 +1101,7 @@ nsSHistory::GloballyEvictContentViewers()
for (uint32_t j = 0; j < shTransactions.Length(); j++) {
TransactionAndDistance &container = shTransactions[j];
if (container.mViewer == contentViewer) {
container.mDistance = std::min(container.mDistance,
std::abs(i - shist->mIndex));
container.mDistance = std::min(container.mDistance, Abs(i - shist->mIndex));
found = true;
break;
}
@ -1112,7 +1110,7 @@ nsSHistory::GloballyEvictContentViewers()
// If we didn't find a TransactionAndDistance for this content viewer, make a new
// one.
if (!found) {
TransactionAndDistance container(trans, std::abs(i - shist->mIndex));
TransactionAndDistance container(trans, Abs(i - shist->mIndex));
shTransactions.AppendElement(container);
}
}

View File

@ -7,6 +7,7 @@
#include <stdlib.h>
#include "mozilla/Assertions.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/Preferences.h"
#include "mozilla/Selection.h"
#include "mozilla/dom/Element.h"
@ -54,8 +55,6 @@
#include "nsThreadUtils.h"
#include "nsUnicharUtils.h"
#include "nsWSRunObject.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
#include <algorithm>
class nsISupports;
@ -1929,7 +1928,7 @@ nsHTMLEditRules::WillDeleteSelection(Selection* aSelection,
res = nsWSRunObject::PrepareToDeleteRange(mHTMLEditor, address_of(visNode), &so, address_of(visNode), &eo);
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIDOMCharacterData> nodeAsText(do_QueryInterface(visNode));
res = mHTMLEditor->DeleteText(nodeAsText, std::min(so, eo), std::abs(eo - so));
res = mHTMLEditor->DeleteText(nodeAsText, std::min(so, eo), Abs(eo - so));
*aHandled = true;
NS_ENSURE_SUCCESS(res, res);
res = InsertBRIfNeeded(aSelection);
@ -4389,7 +4388,7 @@ nsHTMLEditRules::CreateStyleForInsertText(nsISelection *aSelection,
if (relFontSize) {
// dir indicated bigger versus smaller. 1 = bigger, -1 = smaller
int32_t dir = relFontSize > 0 ? 1 : -1;
for (int32_t j = 0; j < abs(relFontSize); j++) {
for (int32_t j = 0; j < Abs(relFontSize); j++) {
res = mHTMLEditor->RelativeFontChangeOnTextNode(dir, nodeAsText,
0, -1);
NS_ENSURE_SUCCESS(res, res);

View File

@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/LookAndFeel.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/Preferences.h"
#include "mozilla/mozalloc.h"
#include "nsAString.h"
@ -42,8 +43,6 @@
#include "nsStringFwd.h"
#include "nsSubstringTuple.h"
#include "nscore.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
#include <algorithm>
class nsISelection;
@ -876,8 +875,8 @@ nsHTMLEditor::MouseMove(nsIDOMEvent* aMouseEvent)
int32_t yThreshold =
LookAndFeel::GetInt(LookAndFeel::eIntID_DragThresholdY, 1);
if (std::abs(clientX - mOriginalX ) * 2 >= xThreshold ||
std::abs(clientY - mOriginalY ) * 2 >= yThreshold) {
if (Abs(clientX - mOriginalX) * 2 >= xThreshold ||
Abs(clientY - mOriginalY) * 2 >= yThreshold) {
mGrabberClicked = false;
StartMoving(nullptr);
}

View File

@ -3,12 +3,11 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/layers/PLayersChild.h"
#include "mozilla/MathAlgorithms.h"
#include "BasicTiledThebesLayer.h"
#include "gfxImageSurface.h"
#include "sampler.h"
#include "gfxPlatform.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
#ifdef GFX_TILEDLAYER_DEBUG_OVERLAY
#include "cairo.h"
@ -377,7 +376,7 @@ BasicTiledThebesLayer::ComputeProgressiveUpdateRegion(BasicTiledLayerBuffer& aTi
if (!aRegionToPaint.IsEmpty()) {
break;
}
if (std::abs(scrollDiffY) >= std::abs(scrollDiffX)) {
if (Abs(scrollDiffY) >= Abs(scrollDiffX)) {
tileBounds.x += incX;
} else {
tileBounds.y += incY;

View File

@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/DebugOnly.h"
#include "mozilla/MathAlgorithms.h"
#ifdef MOZ_LOGGING
#define FORCE_PR_LOG /* Allow logging in the release build */
@ -48,8 +49,6 @@
#include "sampler.h"
#include <algorithm>
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
using namespace mozilla;
using namespace mozilla::gfx;
@ -788,7 +787,7 @@ CalcStyleMatch(gfxFontEntry *aFontEntry, const gfxFontStyle *aStyle)
}
// measure of closeness of weight to the desired value
rank += 9 - abs(aFontEntry->Weight() / 100 - aStyle->ComputeWeight());
rank += 9 - Abs(aFontEntry->Weight() / 100 - aStyle->ComputeWeight());
} else {
// if no font to match, prefer non-bold, non-italic fonts
if (!aFontEntry->IsItalic()) {
@ -2964,8 +2963,8 @@ gfxFont::InitMetricsFromSfntTables(Metrics& aMetrics)
uint16_t(os2->version) >= 2) {
// version 2 and later includes the x-height field
SET_SIGNED(xHeight, os2->sxHeight);
// std::abs because of negative xHeight seen in Kokonor (Tibetan) font
aMetrics.xHeight = std::abs(aMetrics.xHeight);
// Abs because of negative xHeight seen in Kokonor (Tibetan) font
aMetrics.xHeight = Abs(aMetrics.xHeight);
}
// this should always be present
if (os2data.Length() >= offsetof(OS2Table, yStrikeoutPosition) +

View File

@ -5,6 +5,8 @@
* 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 "mozilla/MathAlgorithms.h"
#include <math.h>
#include <stdio.h>
@ -20,6 +22,8 @@
using namespace js;
using namespace js::ion;
using mozilla::Abs;
// This algorithm is based on the paper "Eliminating Range Checks Using
// Static Single Assignment Form" by Gough and Klaren.
//
@ -668,8 +672,7 @@ MAbs::computeRange()
Range other(getOperand(0));
Range *range = new Range(0,
Max(Range::abs64((int64_t) other.lower()),
Range::abs64((int64_t) other.upper())),
Max(Abs<int64_t>(other.lower()), Abs<int64_t>(other.upper())),
other.isDecimal(),
other.exponent());
setRange(range);
@ -716,8 +719,8 @@ MMod::computeRange()
return;
Range lhs(getOperand(0));
Range rhs(getOperand(1));
int64_t a = Range::abs64((int64_t) rhs.lower());
int64_t b = Range::abs64((int64_t) rhs.upper());
int64_t a = Abs<int64_t>(rhs.lower());
int64_t b = Abs<int64_t>(rhs.upper());
if (a == 0 && b == 0)
return;
int64_t bound = Max(1-a, b-1);

View File

@ -9,6 +9,7 @@
#define jsion_range_analysis_h__
#include "mozilla/FloatingPoint.h"
#include "mozilla/MathAlgorithms.h"
#include "wtf/Platform.h"
#include "MIR.h"
@ -199,14 +200,6 @@ class Range : public TempObject {
static Range *Truncate(int64_t l, int64_t h);
static int64_t abs64(int64_t x) {
#ifdef WTF_OS_WINDOWS
return _abs64(x);
#else
return llabs(x);
#endif
}
void print(Sprinter &sp) const;
bool update(const Range *other);
bool update(const Range &other) {
@ -351,7 +344,8 @@ class Range : public TempObject {
return;
}
uint32_t max = Max(abs64((int64_t) lower()), abs64((int64_t) upper()));
uint32_t max = Max(mozilla::Abs<int64_t>(lower()),
mozilla::Abs<int64_t>(upper()));
JS_ASSERT_IF(lower() == JSVAL_INT_MIN, max == (uint32_t) JSVAL_INT_MIN);
JS_ASSERT(max <= (uint32_t) JSVAL_INT_MIN);
// The number of bits needed to encode |max| is the power of 2 plus one.

View File

@ -8,13 +8,15 @@
#ifndef jsion_cpu_arm_assembler_h__
#define jsion_cpu_arm_assembler_h__
#include "mozilla/MathAlgorithms.h"
#include "mozilla/Util.h"
#include "ion/shared/Assembler-shared.h"
#include "assembler/assembler/AssemblerBufferWithConstantPool.h"
#include "ion/CompactBuffer.h"
#include "ion/IonCode.h"
#include "ion/arm/Architecture-arm.h"
#include "ion/shared/IonAssemblerBufferWithConstantPools.h"
#include "mozilla/Util.h"
namespace js {
namespace ion {
@ -703,7 +705,7 @@ class DtrOffImm : public DtrOff
{
public:
DtrOffImm(int32_t imm)
: DtrOff(datastore::Imm12Data(abs(imm)), imm >= 0 ? IsUp : IsDown)
: DtrOff(datastore::Imm12Data(mozilla::Abs(imm)), imm >= 0 ? IsUp : IsDown)
{
JS_ASSERT((imm < 4096) && (imm > -4096));
}
@ -788,7 +790,7 @@ class EDtrOffImm : public EDtrOff
{
public:
EDtrOffImm(int32_t imm)
: EDtrOff(datastore::Imm8Data(abs(imm)), (imm >= 0) ? IsUp : IsDown)
: EDtrOff(datastore::Imm8Data(mozilla::Abs(imm)), (imm >= 0) ? IsUp : IsDown)
{ }
};
@ -836,7 +838,7 @@ class VFPOffImm : public VFPOff
{
public:
VFPOffImm(int32_t imm)
: VFPOff(datastore::Imm8VFPOffData(abs(imm) >> 2), imm < 0 ? IsDown : IsUp)
: VFPOff(datastore::Imm8VFPOffData(mozilla::Abs(imm) >> 2), imm < 0 ? IsDown : IsUp)
{ }
};
class VFPAddr

View File

@ -6,6 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/DebugOnly.h"
#include "mozilla/MathAlgorithms.h"
#include "ion/arm/MacroAssembler-arm.h"
#include "ion/MoveEmitter.h"
@ -13,6 +14,8 @@
using namespace js;
using namespace ion;
using mozilla::Abs;
bool
isValueDTRDCandidate(ValueOperand &val)
{
@ -2523,7 +2526,7 @@ MacroAssemblerARMCompat::storeValue(ValueOperand val, Operand dst) {
void
MacroAssemblerARMCompat::storeValue(ValueOperand val, const BaseIndex &dest)
{
if (isValueDTRDCandidate(val) && (abs(dest.offset) <= 255)) {
if (isValueDTRDCandidate(val) && Abs(dest.offset) <= 255) {
Register tmpIdx;
if (dest.offset == 0) {
if (dest.scale == TimesOne) {
@ -2547,7 +2550,7 @@ MacroAssemblerARMCompat::storeValue(ValueOperand val, const BaseIndex &dest)
void
MacroAssemblerARMCompat::loadValue(const BaseIndex &addr, ValueOperand val)
{
if (isValueDTRDCandidate(val) && (abs(addr.offset) <= 255)) {
if (isValueDTRDCandidate(val) && Abs(addr.offset) <= 255) {
Register tmpIdx;
if (addr.offset == 0) {
if (addr.scale == TimesOne) {

View File

@ -11,6 +11,7 @@
#include "mozilla/Constants.h"
#include "mozilla/FloatingPoint.h"
#include "mozilla/MathAlgorithms.h"
#include <stdlib.h>
#include "jstypes.h"
@ -30,6 +31,8 @@
using namespace js;
using mozilla::Abs;
#ifndef M_E
#define M_E 2.7182818284590452354
#endif
@ -102,7 +105,7 @@ js_math_abs(JSContext *cx, unsigned argc, Value *vp)
}
if (!ToNumber(cx, vp[2], &x))
return JS_FALSE;
z = fabs(x);
z = Abs(x);
vp->setNumber(z);
return JS_TRUE;
}

View File

@ -4,9 +4,13 @@
* 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 "mozilla/MathAlgorithms.h"
#include "jsbool.h"
#include "jslibmath.h"
#include "jsnum.h"
#include "methodjit/MethodJIT.h"
#include "methodjit/Compiler.h"
#include "methodjit/StubCalls.h"
@ -17,6 +21,8 @@ using namespace js::mjit;
using namespace js::analyze;
using namespace JSC;
using mozilla::Abs;
typedef JSC::MacroAssembler::FPRegisterID FPRegisterID;
bool
@ -327,7 +333,8 @@ mjit::Compiler::jsop_binary_double(FrameEntry *lhs, FrameEntry *rhs, JSOp op,
(type == JSVAL_TYPE_INT32 ||
(type == JSVAL_TYPE_UNKNOWN &&
!(lhs->isConstant() && lhs->isType(JSVAL_TYPE_INT32) &&
abs(lhs->getValue().toInt32()) == 1)))) {
Abs(lhs->getValue().toInt32()) == 1))))
{
RegisterID reg = frame.allocReg();
FPRegisterID fpReg = frame.allocFPReg();
JumpList isDouble;

View File

@ -5,6 +5,8 @@
* 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 "mozilla/MathAlgorithms.h"
#include "methodjit/Compiler.h"
#include "methodjit/LoopState.h"
#include "methodjit/FrameState-inl.h"
@ -17,6 +19,8 @@ using namespace js::mjit;
using namespace js::analyze;
using namespace js::types;
using mozilla::Abs;
LoopState::LoopState(JSContext *cx, analyze::CrossScriptSSA *ssa,
mjit::Compiler *cc, FrameState *frame)
: cx(cx), ssa(ssa),
@ -2025,7 +2029,7 @@ LoopState::computeInterval(const CrossSSAValue &cv, int32_t *pmin, int32_t *pmax
if (!computeInterval(rhsv, &rhsmin, &rhsmax) || rhsmin != rhsmax)
return false;
int32_t rhs = abs(rhsmax);
int32_t rhs = Abs(rhsmax);
*pmin = -(rhs - 1);
*pmax = rhs - 1;
return true;
@ -2055,8 +2059,8 @@ LoopState::computeInterval(const CrossSSAValue &cv, int32_t *pmin, int32_t *pmax
CrossSSAValue rhsv(cv.frame, analysis->poppedValue(pc, 0));
if (!computeInterval(lhsv, &lhsmin, &lhsmax) || !computeInterval(rhsv, &rhsmin, &rhsmax))
return false;
int32_t nlhs = Max(abs(lhsmin), abs(lhsmax));
int32_t nrhs = Max(abs(rhsmin), abs(rhsmax));
int32_t nlhs = Max(Abs(lhsmin), Abs(lhsmax));
int32_t nrhs = Max(Abs(rhsmin), Abs(rhsmax));
if (!SafeMul(nlhs, nrhs, pmax))
return false;

View File

@ -4,9 +4,10 @@
* 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/. */
/*
* PR time code.
*/
/* PR time code. */
#include "mozilla/MathAlgorithms.h"
#ifdef SOLARIS
#define _REENTRANT 1
#endif
@ -28,7 +29,6 @@
#ifdef XP_WIN
#include <windef.h>
#include <winbase.h>
#include <math.h> /* for fabs */
#include <mmsystem.h> /* for timeBegin/EndPeriod */
/* VC++ 8.0 or later */
#if _MSC_VER >= 1400
@ -358,7 +358,7 @@ PRMJ_Now(void)
itself, but I have only seen it triggered by another program
doing some kind of file I/O. The symptoms are a negative diff
followed by an equally large positive diff. */
if (fabs(diff) > 2*skewThreshold) {
if (mozilla::Abs(diff) > 2 * skewThreshold) {
/*fprintf(stderr,"Clock skew detected (diff = %f)!\n", diff);*/
if (calibrated) {

View File

@ -8,6 +8,7 @@
#define DateTime_h___
#include "mozilla/FloatingPoint.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/StandardInteger.h"
#include <math.h>
@ -41,7 +42,7 @@ inline double
TimeClip(double time)
{
/* Steps 1-2. */
if (!MOZ_DOUBLE_IS_FINITE(time) || fabs(time) > 8.64e15)
if (!MOZ_DOUBLE_IS_FINITE(time) || mozilla::Abs(time) > 8.64e15)
return js_NaN;
/* Step 3. */

View File

@ -8,16 +8,16 @@
#ifndef __nsCSSColorUtils_h
#define __nsCSSColorUtils_h
#include "mozilla/MathAlgorithms.h"
#include "nsColor.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
// "Sufficient contrast" is determined by
// "Techniques For Accessibility Evalution And Repair Tools".
// See http://www.w3.org/TR/AERT#color-contrast
#define NS_SUFFICIENT_LUMINOSITY_DIFFERENCE 125000
#define NS_LUMINOSITY_DIFFERENCE(a, b) \
std::abs(NS_GetLuminosity(a) - NS_GetLuminosity(b))
mozilla::Abs(NS_GetLuminosity(a) - NS_GetLuminosity(b))
// To determine colors based on the background brightness and border color
void NS_GetSpecial3DColors(nscolor aResult[2],

View File

@ -6,12 +6,11 @@
/* utility functions for drawing borders and backgrounds */
#include <cmath> // for std::abs(float/double)
#include <cstdlib> // for std::abs(int/long)
#include <ctime>
#include "mozilla/DebugOnly.h"
#include "mozilla/HashFunctions.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/Types.h"
#include "nsStyleConsts.h"
@ -1986,10 +1985,10 @@ ComputeRadialGradientLine(nsPresContext* aPresContext,
// Compute gradient shape: the x and y radii of an ellipse.
double radiusX, radiusY;
double leftDistance = std::abs(aLineStart->x);
double rightDistance = std::abs(aBoxSize.width - aLineStart->x);
double topDistance = std::abs(aLineStart->y);
double bottomDistance = std::abs(aBoxSize.height - aLineStart->y);
double leftDistance = Abs(aLineStart->x);
double rightDistance = Abs(aBoxSize.width - aLineStart->x);
double topDistance = Abs(aLineStart->y);
double bottomDistance = Abs(aBoxSize.height - aLineStart->y);
switch (aGradient->mSize) {
case NS_STYLE_GRADIENT_SIZE_CLOSEST_SIDE:
radiusX = std::min(leftDistance, rightDistance);

View File

@ -7,12 +7,10 @@
#include "nsTextFrame.h"
#include <cmath> // for std::abs(float/double)
#include <cstdlib> // for std::abs(int/long)
#include "mozilla/Attributes.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/Likely.h"
#include "mozilla/MathAlgorithms.h"
#include "nsCOMPtr.h"
#include "nsBlockFrame.h"
@ -5648,7 +5646,7 @@ nsTextFrame::PaintTextSelectionDecorations(gfxContext* aCtx,
if (type == aSelectionType) {
pt.x = (aFramePt.x + xOffset -
(mTextRun->IsRightToLeft() ? advance : 0)) / app;
gfxFloat width = std::abs(advance) / app;
gfxFloat width = Abs(advance) / app;
gfxFloat xInFrame = pt.x - (aFramePt.x / app);
DrawSelectionDecorations(aCtx, dirtyRect, aSelectionType, this,
aTextPaintStyle, selectedStyle, pt, xInFrame,

View File

@ -3,6 +3,8 @@
* 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 "mozilla/MathAlgorithms.h"
#include "nsCOMPtr.h"
#include "nsFrame.h"
#include "nsPresContext.h"
@ -30,8 +32,6 @@
#include "nsMathMLOperators.h"
#include "nsMathMLChar.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
#include <algorithm>
using namespace mozilla;
@ -747,7 +747,7 @@ IsSizeOK(nsPresContext* aPresContext, nscoord a, nscoord b, uint32_t aHint)
// or in sloppy markups without protective <mrow></mrow>
bool isNormal =
(aHint & NS_STRETCH_NORMAL)
&& bool(float(std::abs(a - b))
&& bool(float(Abs(a - b))
< (1.0f - NS_MATHML_DELIMITER_FACTOR) * float(b));
// Nearer: True if 'a' is around max{ +/-10% of 'b' , 'b' - 5pt },
// as documented in The TeXbook, Ch.17, p.152.
@ -757,7 +757,7 @@ IsSizeOK(nsPresContext* aPresContext, nscoord a, nscoord b, uint32_t aHint)
float c = std::max(float(b) * NS_MATHML_DELIMITER_FACTOR,
float(b) - nsPresContext::
CSSPointsToAppUnits(NS_MATHML_DELIMITER_SHORTFALL_POINTS));
isNearer = bool(float(std::abs(b - a)) <= (float(b) - c));
isNearer = bool(float(Abs(b - a)) <= (float(b) - c));
}
// Smaller: Mainly for transitory use, to compare two candidate
// choices
@ -784,7 +784,7 @@ IsSizeBetter(nscoord a, nscoord olda, nscoord b, uint32_t aHint)
return (a <= olda) ? (olda > b) : (a <= b);
// XXXkt prob want log scale here i.e. 1.5 is closer to 1 than 0.5
return std::abs(a - b) < std::abs(olda - b);
return Abs(a - b) < Abs(olda - b);
}
// We want to place the glyphs even when they don't fit at their

View File

@ -5,8 +5,8 @@
/* Utilities for animation of computed style values */
#include "mozilla/Util.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/Util.h"
#include "nsStyleAnimation.h"
#include "nsStyleTransformMatrix.h"
@ -24,8 +24,6 @@
#include "mozilla/Likely.h"
#include "gfxMatrix.h"
#include "gfxQuaternion.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
using namespace mozilla;
@ -383,7 +381,7 @@ nsStyleAnimation::ComputeDistance(nsCSSProperty aProperty,
// just like eUnit_Integer.
int32_t startInt = aStartValue.GetIntValue();
int32_t endInt = aEndValue.GetIntValue();
aDistance = std::abs(endInt - startInt);
aDistance = Abs(endInt - startInt);
return true;
}
default:
@ -406,19 +404,19 @@ nsStyleAnimation::ComputeDistance(nsCSSProperty aProperty,
case eUnit_Integer: {
int32_t startInt = aStartValue.GetIntValue();
int32_t endInt = aEndValue.GetIntValue();
aDistance = std::abs(endInt - startInt);
aDistance = Abs(endInt - startInt);
return true;
}
case eUnit_Coord: {
nscoord startCoord = aStartValue.GetCoordValue();
nscoord endCoord = aEndValue.GetCoordValue();
aDistance = fabs(double(endCoord - startCoord));
aDistance = Abs<double>(endCoord - startCoord);
return true;
}
case eUnit_Percent: {
float startPct = aStartValue.GetPercentValue();
float endPct = aEndValue.GetPercentValue();
aDistance = fabs(double(endPct - startPct));
aDistance = Abs<double>(endPct - startPct);
return true;
}
case eUnit_Float: {
@ -436,7 +434,7 @@ nsStyleAnimation::ComputeDistance(nsCSSProperty aProperty,
float startFloat = aStartValue.GetFloatValue();
float endFloat = aEndValue.GetFloatValue();
aDistance = fabs(double(endFloat - startFloat));
aDistance = Abs<double>(endFloat - startFloat);
return true;
}
case eUnit_Color: {
@ -1299,7 +1297,7 @@ Decompose2DMatrix(const gfxMatrix &aMatrix, gfxPoint3D &aScale,
XYshear /= scaleY;
// A*D - B*C should now be 1 or -1
NS_ASSERTION(0.99 < std::abs(A*D - B*C) && std::abs(A*D - B*C) < 1.01,
NS_ASSERTION(0.99 < Abs(A*D - B*C) && Abs(A*D - B*C) < 1.01,
"determinant should now be 1 or -1");
if (A * D < B * C) {
A = -A;

View File

@ -3,6 +3,10 @@
/* 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 "mozilla/Likely.h"
#include "mozilla/MathAlgorithms.h"
#include "nsCOMPtr.h"
#include "nsTableFrame.h"
#include "nsRenderingContext.h"
@ -38,9 +42,6 @@
#include "nsDisplayList.h"
#include "nsIScrollableFrame.h"
#include "nsCSSProps.h"
#include "mozilla/Likely.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
#include <algorithm>
using namespace mozilla;
@ -6246,7 +6247,7 @@ BCPaintBorderIterator::SetDamageArea(const nsRect& aDirtyRect)
if (!haveIntersect)
return false;
mDamageArea = nsIntRect(startColIndex, startRowIndex,
1 + std::abs(int32_t(endColIndex - startColIndex)),
1 + Abs<int32_t>(endColIndex - startColIndex),
1 + endRowIndex - startRowIndex);
Reset();

View File

@ -3,10 +3,8 @@
* 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 <cmath> // for std::abs(float/double)
#include <cstdlib> // for std::abs(int/long)
#include "mozilla/DebugOnly.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/Likely.h"
#include "nsCOMPtr.h"
@ -1830,7 +1828,7 @@ nsTreeBodyFrame::RowCountChanged(int32_t aIndex, int32_t aCount)
NS_ASSERTION(rowCount == mRowCount, "row count did not change by the amount suggested, check caller");
#endif
int32_t count = std::abs(aCount);
int32_t count = Abs(aCount);
int32_t last = GetLastVisibleRow();
if (aIndex >= mTopRowIndex && aIndex <= last)
InvalidateRange(aIndex, last);

View File

@ -9,6 +9,11 @@
#define mozilla_MathAlgorithms_h_
#include "mozilla/Assertions.h"
#include "mozilla/StandardInteger.h"
#include "mozilla/TypeTraits.h"
#include <limits.h>
#include <math.h>
namespace mozilla {
@ -42,6 +47,75 @@ EuclidLCM(IntegerType a, IntegerType b)
return (a / EuclidGCD(a, b)) * b;
}
namespace detail {
// For now mozilla::Abs only takes intN_T, the signed natural types, and
// float/double/long double. Feel free to add overloads for other standard,
// signed types if you need them.
template<typename T>
struct SupportedForAbsFixed : FalseType {};
template<> struct SupportedForAbsFixed<int8_t> : TrueType {};
template<> struct SupportedForAbsFixed<int16_t> : TrueType {};
template<> struct SupportedForAbsFixed<int32_t> : TrueType {};
template<> struct SupportedForAbsFixed<int64_t> : TrueType {};
template<typename T>
struct SupportedForAbs : SupportedForAbsFixed<T> {};
template<> struct SupportedForAbs<char> : IntegralConstant<bool, char(-1) < char(0)> {};
template<> struct SupportedForAbs<signed char> : TrueType {};
template<> struct SupportedForAbs<short> : TrueType {};
template<> struct SupportedForAbs<int> : TrueType {};
template<> struct SupportedForAbs<long> : TrueType {};
template<> struct SupportedForAbs<long long> : TrueType {};
template<> struct SupportedForAbs<float> : TrueType {};
template<> struct SupportedForAbs<double> : TrueType {};
template<> struct SupportedForAbs<long double> : TrueType {};
} // namespace detail
template<typename T>
inline typename mozilla::EnableIf<detail::SupportedForAbs<T>::value, T>::Type
Abs(const T t)
{
// The absolute value of the smallest possible value of a signed-integer type
// won't fit in that type (on twos-complement systems -- and we're blithely
// assuming we're on such systems, for the non-<stdint.h> types listed above),
// so assert that the input isn't that value.
//
// This is the case if: the value is non-negative; or if adding one (giving a
// value in the range [-maxvalue, 0]), then negating (giving a value in the
// range [0, maxvalue]), doesn't produce maxvalue (because in twos-complement,
// (minvalue + 1) == -maxvalue).
MOZ_ASSERT(t >= 0 ||
-(t + 1) != T((1ULL << (CHAR_BIT * sizeof(T) - 1)) - 1),
"You can't negate the smallest possible negative integer!");
return t >= 0 ? t : -t;
}
template<>
inline float
Abs<float>(const float f)
{
return fabsf(f);
}
template<>
inline double
Abs<double>(const double d)
{
return fabs(d);
}
template<>
inline long double
Abs<long double>(const long double d)
{
return fabsl(d);
}
} /* namespace mozilla */
#endif /* mozilla_MathAlgorithms_h_ */

View File

@ -3,6 +3,7 @@
* 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 "mozilla/MathAlgorithms.h"
#include "mozilla/Util.h"
#include "nsNativeKeyBindings.h"
@ -14,8 +15,6 @@
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <gdk/gdk.h>
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
using namespace mozilla;
using namespace mozilla::widget;
@ -100,7 +99,7 @@ delete_from_cursor_cb(GtkWidget *w, GtkDeleteType del_type,
if (!cmd)
return; // unsupported command
count = std::abs(count);
count = Abs(count);
for (int i = 0; i < count; ++i) {
gCurrentCallback(cmd, gCurrentCallbackData);
}
@ -170,7 +169,7 @@ move_cursor_cb(GtkWidget *w, GtkMovementStep step, gint count,
return; // unsupported command
count = std::abs(count);
count = Abs(count);
for (int i = 0; i < count; ++i) {
gCurrentCallback(cmd, gCurrentCallbackData);
}

View File

@ -6,6 +6,8 @@
#ifndef nsGUIEvent_h__
#define nsGUIEvent_h__
#include "mozilla/MathAlgorithms.h"
#include "nsCOMArray.h"
#include "nsPoint.h"
#include "nsRect.h"
@ -28,8 +30,6 @@
#include "nsIVariant.h"
#include "nsStyleConsts.h"
#include "nsAutoPtr.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
namespace mozilla {
namespace dom {
@ -1342,7 +1342,7 @@ public:
(lineOrPageDeltaX > 0 && lineOrPageDeltaY < 0)) {
return 0; // We cannot guess the answer in this case.
}
return (std::abs(lineOrPageDeltaX) > std::abs(lineOrPageDeltaY)) ?
return (Abs(lineOrPageDeltaX) > Abs(lineOrPageDeltaY)) ?
lineOrPageDeltaX : lineOrPageDeltaY;
}

View File

@ -54,12 +54,12 @@
**************************************************************
**************************************************************/
#include "mozilla/MathAlgorithms.h"
#include "mozilla/Util.h"
#include "mozilla/ipc/RPCChannel.h"
#include <algorithm>
/* This must occur *after* ipc/RPCChannel.h to avoid typedefs conflicts. */
#include "mozilla/Util.h"
#include "nsWindow.h"
#include <shellapi.h>
@ -119,8 +119,6 @@
#include "WidgetUtils.h"
#include "nsIWidgetListener.h"
#include "nsDOMTouchEvent.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
#ifdef MOZ_ENABLE_D3D9_LAYER
#include "LayerManagerD3D9.h"
@ -3436,7 +3434,7 @@ nsWindow::OverrideSystemMouseScrollSpeed(int32_t aOriginalDelta,
// on the document of SystemParametersInfo in MSDN.
const uint32_t kSystemDefaultScrollingSpeed = 3;
int32_t absOriginDelta = std::abs(aOriginalDelta);
int32_t absOriginDelta = Abs(aOriginalDelta);
// Compute the simple overridden speed.
int32_t absComputedOverriddenDelta;
@ -3864,8 +3862,8 @@ bool nsWindow::DispatchMouseEvent(uint32_t aEventType, WPARAM wParam,
sLastMouseMovePoint.y = mpScreen.y;
}
bool insideMovementThreshold = (abs(sLastMousePoint.x - eventPoint.x) < (short)::GetSystemMetrics(SM_CXDOUBLECLK)) &&
(abs(sLastMousePoint.y - eventPoint.y) < (short)::GetSystemMetrics(SM_CYDOUBLECLK));
bool insideMovementThreshold = (Abs(sLastMousePoint.x - eventPoint.x) < (short)::GetSystemMetrics(SM_CXDOUBLECLK)) &&
(Abs(sLastMousePoint.y - eventPoint.y) < (short)::GetSystemMetrics(SM_CYDOUBLECLK));
BYTE eventButton;
switch (aButton) {
@ -6395,10 +6393,10 @@ bool nsWindow::OnGesture(WPARAM wParam, LPARAM lParam)
if (mDisplayPanFeedback) {
mGesture.UpdatePanFeedbackX(mWnd,
std::abs(RoundDown(wheelEvent.overflowDeltaX)),
Abs(RoundDown(wheelEvent.overflowDeltaX)),
endFeedback);
mGesture.UpdatePanFeedbackY(mWnd,
std::abs(RoundDown(wheelEvent.overflowDeltaY)),
Abs(RoundDown(wheelEvent.overflowDeltaY)),
endFeedback);
mGesture.PanFeedbackFinalize(mWnd, endFeedback);
}

View File

@ -11,13 +11,13 @@
// before this reaches the Release or even Beta channel.
#define FORCE_PR_LOG
#include "mozilla/TimeStamp.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/Mutex.h"
#include "mozilla/TimeStamp.h"
#include <windows.h>
#include "prlog.h"
#include <stdio.h>
#include <cstdlib> // for std::abs(int/long)
#include <intrin.h>
@ -356,7 +356,7 @@ TimeStampValue::CheckQPC(int64_t aDuration, const TimeStampValue &aOther) const
return false;
// Treat absolutely for calibration purposes
aDuration = std::abs(aDuration);
aDuration = Abs(aDuration);
// Check QPC is sane before using it.

View File

@ -8,10 +8,12 @@
* stream.
*/
#include "mozilla/Attributes.h"
#include "mozilla/MathAlgorithms.h"
#include "base/basictypes.h"
#include "nsMultiplexInputStream.h"
#include "mozilla/Attributes.h"
#include "nsIMultiplexInputStream.h"
#include "nsISeekableStream.h"
#include "nsCOMPtr.h"
@ -19,11 +21,11 @@
#include "nsIClassInfoImpl.h"
#include "nsIIPCSerializableInputStream.h"
#include "mozilla/ipc/InputStreamUtils.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
using namespace mozilla::ipc;
using mozilla::Abs;
class nsMultiplexInputStream MOZ_FINAL : public nsIMultiplexInputStream,
public nsISeekableStream,
public nsIIPCSerializableInputStream
@ -513,7 +515,7 @@ nsMultiplexInputStream::Seek(int32_t aWhence, int64_t aOffset)
}
// See if we have enough data in the current stream.
if (std::abs(remaining) < streamPos) {
if (Abs(remaining) < streamPos) {
rv = stream->Seek(NS_SEEK_END, remaining);
NS_ENSURE_SUCCESS(rv, rv);
@ -521,7 +523,7 @@ nsMultiplexInputStream::Seek(int32_t aWhence, int64_t aOffset)
mStartedReadingCurrent = true;
remaining = 0;
} else if (std::abs(remaining) > streamPos) {
} else if (Abs(remaining) > streamPos) {
if (i > oldCurrentStream ||
(i == oldCurrentStream && !oldStartedReadingCurrent)) {
// We're already at start so no need to seek this stream
@ -531,7 +533,7 @@ nsMultiplexInputStream::Seek(int32_t aWhence, int64_t aOffset)
rv = stream->Tell(&avail);
NS_ENSURE_SUCCESS(rv, rv);
int64_t newPos = streamPos + XPCOM_MIN(avail, std::abs(remaining));
int64_t newPos = streamPos + XPCOM_MIN(avail, Abs(remaining));
rv = stream->Seek(NS_SEEK_END, -newPos);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -4,6 +4,8 @@
* 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 "mozilla/MathAlgorithms.h"
// Local includes
#include "nsXULWindow.h"
#include <algorithm>
@ -56,8 +58,6 @@
#include "prenv.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/Element.h"
#include <cstdlib> // for std::abs(int/long)
#include <cmath> // for std::abs(float/double)
using namespace mozilla;
@ -1349,8 +1349,7 @@ void nsXULWindow::StaggerPosition(int32_t &aRequestedX, int32_t &aRequestedY,
listY = NSToIntRound(listY / scale);
}
if (std::abs(listX - aRequestedX) <= kSlop &&
std::abs(listY - aRequestedY) <= kSlop) {
if (Abs(listX - aRequestedX) <= kSlop && Abs(listY - aRequestedY) <= kSlop) {
// collision! offset and start over
if (bouncedX & 0x1)
aRequestedX -= kOffset;