Ignore:
Timestamp:
Jan 28, 2011, 9:02:31 PM (14 years ago)
Author:
Simon Fraser
Message:

2011-01-28 Simon Fraser <Simon Fraser>

Reviewed by Gavin Barraclough.

Add various clampToInt() methods to MathExtras.h
https://bugs.webkit.org/show_bug.cgi?id=52910

Use clampToInteger() from MathExtras.h

  • css/CSSParser.cpp: (WebCore::CSSParser::parseCounter):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/wtf/MathExtras.h

    r74147 r77045  
    2727#define WTF_MathExtras_h
    2828
     29#include <algorithm>
    2930#include <cmath>
    3031#include <float.h>
     32#include <limits>
    3133#include <stdlib.h>
    3234
     
    206208inline float grad2rad(float g) { return g * piFloat / 200.0f; }
    207209
     210inline int clampToInteger(double d)
     211{
     212    const double minIntAsDouble = std::numeric_limits<int>::min();
     213    const double maxIntAsDouble = std::numeric_limits<int>::max();
     214    return static_cast<int>(std::max(std::min(d, maxIntAsDouble), minIntAsDouble));
     215}
     216
     217inline int clampToPositiveInteger(double d)
     218{
     219    const double maxIntAsDouble = std::numeric_limits<int>::max();
     220    return static_cast<int>(std::max<double>(std::min(d, maxIntAsDouble), 0));
     221}
     222
     223inline int clampToInteger(float d)
     224{
     225    const float minIntAsFloat = std::numeric_limits<int>::min();
     226    const float maxIntAsFloat = std::numeric_limits<int>::max();
     227    return static_cast<int>(std::max(std::min(d, maxIntAsFloat), minIntAsFloat));
     228}
     229
     230inline int clampToPositiveInteger(float d)
     231{
     232    const float maxIntAsFloat = std::numeric_limits<int>::max();
     233    return static_cast<int>(std::max<float>(std::min(d, maxIntAsFloat), 0));
     234}
     235
    208236#if !COMPILER(MSVC) && !COMPILER(WINSCW) && !(COMPILER(RVCT) && (OS(SYMBIAN) || PLATFORM(BREWMP)))
    209237using std::isfinite;
Note: See TracChangeset for help on using the changeset viewer.