Skip to content

Commit

Permalink
create core::math namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Constellation committed Feb 2, 2012
1 parent 319bb41 commit 915d49a
Show file tree
Hide file tree
Showing 21 changed files with 141 additions and 140 deletions.
20 changes: 10 additions & 10 deletions iv/conversions.h
Expand Up @@ -39,9 +39,9 @@ inline double ParseIntegerOverflow(const CharT* it,
double number = 0.0;
double multiplier = 1.0;
for (--it, --last; last != it; --last) {
if (multiplier == kInfinity) {
if (multiplier == math::kInfinity) {
if (*last != '0') {
number = kInfinity;
number = math::kInfinity;
break;
}
} else {
Expand Down Expand Up @@ -208,11 +208,11 @@ inline int32_t DoubleToInt32(double d) {
if (static_cast<double>(i) == d) {
return i;
}
if (!IsFinite(d) || d == 0) {
if (!math::IsFinite(d) || d == 0) {
return 0;
}
if (d < 0 || d >= detail::kDoubleToInt32_Two32) {
d = Modulo(d, detail::kDoubleToInt32_Two32);
d = math::Modulo(d, detail::kDoubleToInt32_Two32);
}
d = (d >= 0) ?
std::floor(d) : std::ceil(d) + detail::kDoubleToInt32_Two32;
Expand All @@ -229,14 +229,14 @@ inline int64_t DoubleToInt64(double d) {
if (static_cast<double>(i) == d) {
return i;
}
if (!IsFinite(d) || d == 0) {
if (!math::IsFinite(d) || d == 0) {
return 0;
}
if (detail::kDoubleToInt32_Two32 >= d) {
return static_cast<int64_t>(DoubleToInt32(d));
}
const int32_t lo = DoubleToInt32(
Modulo(d, detail::kDoubleToInt32_Two32));
math::Modulo(d, detail::kDoubleToInt32_Two32));
const int32_t hi = DoubleToInt32(d / detail::kDoubleToInt32_Two32);
return hi * INT64_C(4294967296) + lo;
}
Expand All @@ -246,13 +246,13 @@ inline uint64_t DoubleToUInt64(double d) {
}

inline double DoubleToInteger(double d) {
if (IsNaN(d)) {
if (math::IsNaN(d)) {
return 0;
}
if (!IsFinite(d) || d == 0) {
if (!math::IsFinite(d) || d == 0) {
return d;
}
return std::floor(std::abs(d)) * (Signbit(d) ? -1 : 1);
return std::floor(std::abs(d)) * (math::Signbit(d) ? -1 : 1);
}

template<typename Iter>
Expand Down Expand Up @@ -399,7 +399,7 @@ inline OutputIter DoubleToStringWithRadix(double v, int radix, OutputIter res) {
int integer_pos = kMaxBufSize - 1;
do {
buffer[integer_pos--] =
kHexDigits[static_cast<std::size_t>(Modulo(integer, radix))];
kHexDigits[static_cast<std::size_t>(math::Modulo(integer, radix))];
integer /= radix;
} while (integer >= 1.0);
if (is_negative) {
Expand Down
2 changes: 1 addition & 1 deletion iv/dtoa_bigint.h
Expand Up @@ -643,7 +643,7 @@ inline void DoubleToASCII(Buffer* buf,
IV_STATIC_ASSERT(
RoundingNone + RoundingSignificantFigures + RoundingDecimalPlaces == 1);
IV_STATIC_ASSERT(!RoundingNone || LeftRight);
assert(!IsNaN(dd) && !core::IsInf(dd));
assert(!core::math::IsNaN(dd) && !core::math::IsInf(dd));

U u;
u.d = dd;
Expand Down
30 changes: 15 additions & 15 deletions iv/lv5/date_utils.h
Expand Up @@ -33,7 +33,7 @@ inline double Day(double t) {
}

inline double TimeWithinDay(double t) {
const double res = core::Modulo(t, kMsPerDay);
const double res = core::math::Modulo(t, kMsPerDay);
if (res < 0) {
return res + kMsPerDay;
}
Expand Down Expand Up @@ -144,7 +144,7 @@ static const std::array<const char*, 7> kWeekDays = { {
} };

inline int WeekDay(double t) {
const int res = core::DoubleToInt32(core::Modulo((Day(t) + 4), 7));
const int res = core::DoubleToInt32(core::math::Modulo((Day(t) + 4), 7));
if (res < 0) {
return res + 7;
}
Expand Down Expand Up @@ -185,7 +185,7 @@ inline double DaylightSavingTAFallback(double utc) {
// Daylight Saving Time
// from 2 AM the first Sunday in April
// through 2 AM the last Sunday in October
assert(!core::IsNaN(utc));
assert(!core::math::IsNaN(utc));
const int year = YearFromTime(utc);
const int leap = IsLeapYear(utc);

Expand Down Expand Up @@ -228,7 +228,7 @@ inline double UTC(double t) {

inline int HourFromTime(double t) {
const int res = core::DoubleToInt32(
core::Modulo(std::floor(t / kMsPerHour), kHoursPerDay));
core::math::Modulo(std::floor(t / kMsPerHour), kHoursPerDay));
if (res < 0) {
return res + kHoursPerDay;
}
Expand All @@ -237,7 +237,7 @@ inline int HourFromTime(double t) {

inline int MinFromTime(double t) {
const int res = core::DoubleToInt32(
core::Modulo(std::floor(t / kMsPerMinute), kMinutesPerHour));
core::math::Modulo(std::floor(t / kMsPerMinute), kMinutesPerHour));
if (res < 0) {
return res + kMinutesPerHour;
}
Expand All @@ -246,26 +246,26 @@ inline int MinFromTime(double t) {

inline int SecFromTime(double t) {
const int res = core::DoubleToInt32(
core::Modulo(std::floor(t / kMsPerSecond), kSecondsPerMinute));
core::math::Modulo(std::floor(t / kMsPerSecond), kSecondsPerMinute));
if (res < 0) {
return res + kSecondsPerMinute;
}
return res;
}

inline int MsFromTime(double t) {
const int res = core::DoubleToInt32(core::Modulo(t, kMsPerSecond));
const int res = core::DoubleToInt32(core::math::Modulo(t, kMsPerSecond));
if (res < 0) {
return res + kMsPerSecond;
}
return res;
}

inline double MakeTime(double hour, double min, double sec, double ms) {
if (!core::IsFinite(hour) ||
!core::IsFinite(min) ||
!core::IsFinite(sec) ||
!core::IsFinite(ms)) {
if (!core::math::IsFinite(hour) ||
!core::math::IsFinite(min) ||
!core::math::IsFinite(sec) ||
!core::math::IsFinite(ms)) {
return core::kNaN;
} else {
return
Expand All @@ -289,9 +289,9 @@ inline double DateToDays(int year, int month, int date) {
}

inline double MakeDay(double year, double month, double date) {
if (!core::IsFinite(year) ||
!core::IsFinite(month) ||
!core::IsFinite(date)) {
if (!core::math::IsFinite(year) ||
!core::math::IsFinite(month) ||
!core::math::IsFinite(date)) {
return core::kNaN;
} else {
const int y = core::DoubleToInt32(year);
Expand All @@ -312,7 +312,7 @@ inline double MakeDate(double day, double time) {
}

inline double TimeClip(double time) {
if (!core::IsFinite(time)) {
if (!core::math::IsFinite(time)) {
return core::kNaN;
}
if (std::abs(time) > kMaxTime) {
Expand Down
4 changes: 2 additions & 2 deletions iv/lv5/date_utils_posix.h
Expand Up @@ -10,7 +10,7 @@ namespace date {

inline double DaylightSavingTA(double utc) {
// t is utc time
if (core::IsNaN(utc)) {
if (core::math::IsNaN(utc)) {
return utc;
}
const std::time_t current =
Expand Down Expand Up @@ -40,7 +40,7 @@ inline double HighResTime() {
}

inline const char* LocalTimeZone(double t) {
if (core::IsNaN(t)) {
if (core::math::IsNaN(t)) {
return "";
}
const std::time_t tv = static_cast<time_t>(std::floor(t / kMsPerSecond));
Expand Down
4 changes: 2 additions & 2 deletions iv/lv5/date_utils_win.h
Expand Up @@ -47,7 +47,7 @@ inline std::time_t SystemTimeToUnixTime(const SYSTEMTIME& st) {
inline double DaylightSavingTA(double utc) {
// GetTimeZoneInformation
// http://msdn.microsoft.com/en-us/library/ms724421(VS.85).aspx
if (core::IsNaN(utc)) {
if (core::math::IsNaN(utc)) {
return utc;
}
TIME_ZONE_INFORMATION tzi;
Expand Down Expand Up @@ -164,7 +164,7 @@ inline std::array<char, kMaxTZNameSize> LocalTimeZoneImpl(double t) {
}

inline const char* LocalTimeZone(double t) {
if (core::IsNaN(t)) {
if (core::math::IsNaN(t)) {
return "";
}
static const std::array<char, kMaxTZNameSize> kTZ = LocalTimeZoneImpl(t);
Expand Down
2 changes: 1 addition & 1 deletion iv/lv5/json_stringifier.h
Expand Up @@ -291,7 +291,7 @@ class JSONStringifier : private core::Noncopyable<> {
}
if (value.IsNumber()) {
const double val = value.number();
if (core::IsFinite(val)) {
if (core::math::IsFinite(val)) {
return value.ToString(ctx_, e);
} else {
return JSString::NewAsciiString(ctx_, "null");
Expand Down
14 changes: 7 additions & 7 deletions iv/lv5/jsval.h
Expand Up @@ -181,7 +181,7 @@ void JSVal::set_value_uint32(uint32_t val) {

void JSVal::set_value(double val) {
const int32_t i = static_cast<int32_t>(val);
if (val != i || (!i && core::Signbit(val))) {
if (val != i || (!i && core::math::Signbit(val))) {
// this value is not represented by int32_t
value_.bytes_ = (val == val) ?
(core::BitCast<uint64_t>(val) + detail::jsval64::kDoubleOffset) :
Expand Down Expand Up @@ -244,9 +244,9 @@ bool JSVal::SameValue(const this_type& lhs, const this_type& rhs) {
const double lhsv = lhs.number();
const double rhsv = rhs.number();
if (lhsv == rhsv) {
return core::Signbit(lhsv) == core::Signbit(rhsv);
return core::math::Signbit(lhsv) == core::math::Signbit(rhsv);
} else {
return core::IsNaN(lhsv) && core::IsNaN(rhsv);
return core::math::IsNaN(lhsv) && core::math::IsNaN(rhsv);
}
}

Expand Down Expand Up @@ -435,7 +435,7 @@ void JSVal::set_value_uint32(uint32_t val) {

void JSVal::set_value(double val) {
const int32_t i = static_cast<int32_t>(val);
if (val != i || (!i && core::Signbit(val))) {
if (val != i || (!i && core::math::Signbit(val))) {
// this value is not represented by int32_t
value_.number_.as_ = (val == val) ? val : core::kNaN;
} else {
Expand Down Expand Up @@ -500,9 +500,9 @@ bool JSVal::SameValue(const this_type& lhs, const this_type& rhs) {
const double lhsv = lhs.number();
const double rhsv = rhs.number();
if (lhsv == rhsv) {
return core::Signbit(lhsv) == core::Signbit(rhsv);
return core::math::Signbit(lhsv) == core::math::Signbit(rhsv);
} else {
return core::IsNaN(lhsv) && core::IsNaN(rhsv);
return core::math::IsNaN(lhsv) && core::math::IsNaN(rhsv);
}
}
if (lhs.IsString()) {
Expand Down Expand Up @@ -746,7 +746,7 @@ JSVal JSVal::ToNumberValue(Context* ctx, Error* e) const {
bool JSVal::ToBoolean(Error* e) const {
if (IsNumber()) {
const double num = number();
return num != 0 && !core::IsNaN(num);
return num != 0 && !core::math::IsNaN(num);
} else if (IsString()) {
return !string()->empty();
} else if (IsNullOrUndefined()) {
Expand Down
2 changes: 1 addition & 1 deletion iv/lv5/jsval_fwd.h
Expand Up @@ -388,7 +388,7 @@ class JSVal {
this_type rhs, Error* e);

static inline CompareResult NumberCompare(double lhs, double rhs) {
if (core::IsNaN(lhs) || core::IsNaN(rhs)) {
if (core::math::IsNaN(lhs) || core::math::IsNaN(rhs)) {
return CMP_UNDEFINED;
}
if (lhs == rhs) {
Expand Down
4 changes: 2 additions & 2 deletions iv/lv5/railgun/compiler_expression.h
Expand Up @@ -501,7 +501,7 @@ inline void Compiler::Visit(const NumberLiteral* lit) {
thunklist_.Spill(dst_);
const double val = lit->value();
const int32_t i32 = static_cast<int32_t>(val);
if (val == i32 && (i32 || !core::Signbit(val))) {
if (val == i32 && (i32 || !core::math::Signbit(val))) {
// boxing int32_t
Instruction inst(0u);
inst.i32 = i32;
Expand All @@ -510,7 +510,7 @@ inline void Compiler::Visit(const NumberLiteral* lit) {
}

const uint32_t ui32 = static_cast<uint32_t>(val);
if (val == ui32 && (ui32 || !core::Signbit(val))) {
if (val == ui32 && (ui32 || !core::math::Signbit(val))) {
// boxing uint32_t
Emit<OP::LOAD_UINT32>(dst_, ui32);
return;
Expand Down
2 changes: 1 addition & 1 deletion iv/lv5/railgun/condition.h
Expand Up @@ -54,7 +54,7 @@ class Condition {

if (const NumberLiteral* num = literal->AsNumberLiteral()) {
const double val = num->value();
if (val != 0 && !core::IsNaN(val)) {
if (val != 0 && !core::math::IsNaN(val)) {
return COND_TRUE;
} else {
return COND_FALSE;
Expand Down
2 changes: 1 addition & 1 deletion iv/lv5/railgun/operation.h
Expand Up @@ -416,7 +416,7 @@ class Operation {

JSVal BinaryModulo(const JSVal& lhs, const JSVal& rhs, Error* e) const {
const double left = lhs.ToNumber(ctx_, CHECK);
return core::Modulo(left, rhs.ToNumber(ctx_, e));
return core::math::Modulo(left, rhs.ToNumber(ctx_, e));
}

JSVal BinaryLShift(const JSVal& lhs, const JSVal& rhs, Error* e) const {
Expand Down

0 comments on commit 915d49a

Please sign in to comment.