// class Decimal TEST( Decimal01, Decimals ) { Decimal d; DecimalType expected = 0; DecimalType actual = d.getValue(); CHECK_DOUBLES_EQUAL( expected, actual, kThreshold ) }
void Decimal::co_normalize(Decimal& x, Decimal& y) { if (x.m_places == y.m_places) { // do nothing } else if (x.m_places < y.m_places) { if (x.rescale(y.m_places) != 0) { JEWEL_THROW ( DecimalRangeException, "Unsafe attempt to set fractional precision in course " "of co-normalization attempt." ); } } else { JEWEL_ASSERT (y.m_places < x.m_places); if (y.rescale(x.m_places) != 0) { JEWEL_THROW ( DecimalRangeException, "Unsafe attempt to set fractional precision in course " "of co-normalization attempt." ); } } return; }
bool operator >= (const Decimal &a, const Decimal &b) { if (a.is_neg != b.is_neg) { return !a.is_neg || (a.is_zero() && b.is_zero()); } else if (!a.is_neg) { // a, b >= 0 if (a.integer != b.integer) { return a.integer > b.integer; } for (int i = 0; i < Decimal::len; i++) { if (a.data[i] != b.data[i]) { return a.data[i] > b.data[i]; } } return true; } else { // a, b <= 0 if (a.integer != b.integer) { return a.integer < b.integer; } for (int i = 0; i < Decimal::len; i++) { if (a.data[i] != b.data[i]) { return a.data[i] < b.data[i]; } } return true; } }
void ImplField::setDecimalValue(Decimal value) { type_ = ValueType::DECIMAL; signedInteger_ = value.getMantissa(); exponent_ = value.getExponent(); }
void SliderThumbElement::setPositionFromPoint(const LayoutPoint& absolutePoint) { RefPtr<HTMLInputElement> input = hostInput(); if (!input || !input->renderer() || !renderBox()) return; HTMLElement* trackElement = input->sliderTrackElement(); if (!trackElement->renderBox()) return; // Do all the tracking math relative to the input's renderer's box. RenderBox& inputRenderer = downcast<RenderBox>(*input->renderer()); RenderBox& trackRenderer = *trackElement->renderBox(); bool isVertical = hasVerticalAppearance(input.get()); bool isLeftToRightDirection = renderBox()->style().isLeftToRightDirection(); LayoutPoint offset(inputRenderer.absoluteToLocal(absolutePoint, UseTransforms)); FloatRect trackBoundingBox = trackRenderer.localToContainerQuad(FloatRect(0, 0, trackRenderer.width(), trackRenderer.height()), &inputRenderer).enclosingBoundingBox(); LayoutUnit trackLength; LayoutUnit position; if (isVertical) { trackLength = trackRenderer.contentHeight() - renderBox()->height(); position = offset.y() - renderBox()->height() / 2 - trackBoundingBox.y() - renderBox()->marginBottom(); } else { trackLength = trackRenderer.contentWidth() - renderBox()->width(); position = offset.x() - renderBox()->width() / 2 - trackBoundingBox.x(); position -= isLeftToRightDirection ? renderBox()->marginLeft() : renderBox()->marginRight(); } position = std::max<LayoutUnit>(0, std::min(position, trackLength)); const Decimal ratio = Decimal::fromDouble(static_cast<double>(position) / trackLength); const Decimal fraction = isVertical || !isLeftToRightDirection ? Decimal(1) - ratio : ratio; StepRange stepRange(input->createStepRange(RejectAny)); Decimal value = stepRange.clampValue(stepRange.valueFromProportion(fraction)); #if ENABLE(DATALIST_ELEMENT) const LayoutUnit snappingThreshold = renderer()->theme().sliderTickSnappingThreshold(); if (snappingThreshold > 0) { Decimal closest = input->findClosestTickMarkValue(value); if (closest.isFinite()) { double closestFraction = stepRange.proportionFromValue(closest).toDouble(); double closestRatio = isVertical || !isLeftToRightDirection ? 1.0 - closestFraction : closestFraction; LayoutUnit closestPosition = trackLength * closestRatio; if ((closestPosition - position).abs() <= snappingThreshold) value = closest; } } #endif String valueString = serializeForNumberType(value); if (valueString == input->value()) return; // FIXME: This is no longer being set from renderer. Consider updating the method name. input->setValueFromRenderer(valueString); if (renderer()) renderer()->setNeedsLayout(); }
std::pair<String, String> InputType::validationMessage(const InputTypeView& inputTypeView) const { const String value = element().value(); // The order of the following checks is meaningful. e.g. We'd like to show the // badInput message even if the control has other validation errors. if (inputTypeView.hasBadInput()) return std::make_pair(badInputText(), emptyString()); if (valueMissing(value)) return std::make_pair(valueMissingText(), emptyString()); if (typeMismatch()) return std::make_pair(typeMismatchText(), emptyString()); if (patternMismatch(value)) { // https://html.spec.whatwg.org/multipage/forms.html#attr-input-pattern // When an input element has a pattern attribute specified, authors // should include a title attribute to give a description of the // pattern. User agents may use the contents of this attribute, if it // is present, when informing the user that the pattern is not matched return std::make_pair(locale().queryString(WebLocalizedString::ValidationPatternMismatch), element().fastGetAttribute(titleAttr).getString()); } if (element().tooLong()) return std::make_pair(locale().validationMessageTooLongText(value.length(), element().maxLength()), emptyString()); if (element().tooShort()) return std::make_pair(locale().validationMessageTooShortText(value.length(), element().minLength()), emptyString()); if (!isSteppable()) return std::make_pair(emptyString(), emptyString()); const Decimal numericValue = parseToNumberOrNaN(value); if (!numericValue.isFinite()) return std::make_pair(emptyString(), emptyString()); StepRange stepRange(createStepRange(RejectAny)); if (numericValue < stepRange.minimum()) return std::make_pair(rangeUnderflowText(stepRange.minimum()), emptyString()); if (numericValue > stepRange.maximum()) return std::make_pair(rangeOverflowText(stepRange.maximum()), emptyString()); if (stepRange.stepMismatch(numericValue)) { DCHECK(stepRange.hasStep()); Decimal candidate1 = stepRange.clampValue(numericValue); String localizedCandidate1 = localizeValue(serialize(candidate1)); Decimal candidate2 = candidate1 < numericValue ? candidate1 + stepRange.step() : candidate1 - stepRange.step(); if (!candidate2.isFinite() || candidate2 < stepRange.minimum() || candidate2 > stepRange.maximum()) return std::make_pair(locale().queryString(WebLocalizedString::ValidationStepMismatchCloseToLimit, localizedCandidate1), emptyString()); String localizedCandidate2 = localizeValue(serialize(candidate2)); if (candidate1 < candidate2) return std::make_pair(locale().queryString(WebLocalizedString::ValidationStepMismatch, localizedCandidate1, localizedCandidate2), emptyString()); return std::make_pair(locale().queryString(WebLocalizedString::ValidationStepMismatch, localizedCandidate2, localizedCandidate1), emptyString()); } return std::make_pair(emptyString(), emptyString()); }
Decimal InputType::findStepBase(const Decimal& defaultValue) const { Decimal stepBase = parseToNumber(element().fastGetAttribute(minAttr), Decimal::nan()); if (!stepBase.isFinite()) stepBase = parseToNumber(element().fastGetAttribute(valueAttr), defaultValue); return stepBase; }
bool Decimal::operator<(Decimal rhs) const { Decimal lhs = *this; lhs.rationalize(); rhs.rationalize(); if (lhs.m_places == rhs.m_places) { return lhs.m_intval < rhs.m_intval; } bool const left_is_longer = (lhs.m_places > rhs.m_places); Decimal const *const shorter = (left_is_longer? &rhs: &lhs); Decimal const *const longer = (left_is_longer? &lhs: &rhs); places_type const target_places = shorter->m_places; int_type longers_revised_intval = longer->m_intval; int_type const shorters_intval = shorter->m_intval; bool const longer_is_negative = (longers_revised_intval < 0); for ( places_type longers_places = longer->m_places; longers_places != target_places; --longers_places ) { JEWEL_ASSERT (s_base > 0); JEWEL_ASSERT (!division_is_unsafe(longers_revised_intval, s_base)); longers_revised_intval /= s_base; JEWEL_ASSERT (longers_places > 0); } bool longer_is_smaller = ( longer_is_negative? (longers_revised_intval <= shorters_intval): (longers_revised_intval < shorters_intval) ); return ( &lhs == (longer_is_smaller? longer: shorter) ); }
void RangeInputType::handleKeydownEvent(KeyboardEvent* event) { if (element()->isDisabledOrReadOnly()) return; const String& key = event->keyIdentifier(); const Decimal current = parseToNumberOrNaN(element()->value()); ASSERT(current.isFinite()); StepRange stepRange(createStepRange(RejectAny)); // FIXME: We can't use stepUp() for the step value "any". So, we increase // or decrease the value by 1/100 of the value range. Is it reasonable? const Decimal step = equalIgnoringCase(element()->fastGetAttribute(stepAttr), "any") ? (stepRange.maximum() - stepRange.minimum()) / 100 : stepRange.step(); const Decimal bigStep = max((stepRange.maximum() - stepRange.minimum()) / 10, step); bool isVertical = false; if (element()->renderer()) { ControlPart part = element()->renderer()->style()->appearance(); isVertical = part == SliderVerticalPart || part == MediaVolumeSliderPart; } Decimal newValue; if (key == "Up") newValue = current + step; else if (key == "Down") newValue = current - step; else if (key == "Left") newValue = isVertical ? current + step : current - step; else if (key == "Right") newValue = isVertical ? current - step : current + step; else if (key == "PageUp") newValue = current + bigStep; else if (key == "PageDown") newValue = current - bigStep; else if (key == "Home") newValue = isVertical ? stepRange.maximum() : stepRange.minimum(); else if (key == "End") newValue = isVertical ? stepRange.minimum() : stepRange.maximum(); else return; // Did not match any key binding. newValue = stepRange.clampValue(newValue); if (newValue != current) { EventQueueScope scope; ExceptionCode ec; TextFieldEventBehavior eventBehavior = DispatchChangeEvent; setValueAsDecimal(newValue, eventBehavior, ec); if (AXObjectCache::accessibilityEnabled()) element()->document()->axObjectCache()->postNotification(element(), AXObjectCache::AXValueChanged, true); element()->dispatchFormControlChangeEvent(); } event->setDefaultHandled(); }
String serializeForNumberType(const Decimal& number) { if (number.isZero()) { // Decimal::toString appends exponent, e.g. "0e-18" return number.isNegative() ? "-0" : "0"; } return number.toString(); }
bool great<Decimal*, Decimal*>(const void *x,const void *y){ if (((Decimal*)x)->op_equals(*(Decimal*)y)) return false; Decimal tmp = ((Decimal*)x)->op_max(*(Decimal*)y); if (tmp.op_equals(*(Decimal*)x)) return true; return false; }
void CheckDoubleCast(double val) { Decimal dec; dec.AssignDouble(val); BOOST_CHECK_CLOSE(val, dec.ToDouble(), 1E-10); }
bool operator == (const Decimal &a, const Decimal &b) { if (a.is_zero() && b.is_zero()) return true; if (a.is_neg != b.is_neg) return false; if (a.integer != b.integer) return false; for (int i = 0; i < Decimal::len; i++) { if (a.data[i] != b.data[i]) return false; } return true; }
String BaseDateAndTimeInputType::serialize(const Decimal& value) const { if (!value.isFinite()) return String(); DateComponents date; if (!setMillisecondToDateComponents(value.toDouble(), &date)) return String(); return serializeWithComponents(date); }
void CouchbaseRecordBinder::processDecimal(const void *value, unsigned digits, unsigned precision, const RtlFieldInfo * field) { Decimal val; size32_t bytes; rtlDataAttr decText; val.setDecimal(digits, precision, value); val.getStringX(bytes, decText.refstr()); processUtf8(bytes, decText.getstr(), field); }
void SliderThumbElement::setPositionFromPoint(const LayoutPoint& point) { RefPtrWillBeRawPtr<HTMLInputElement> input(hostInput()); Element* trackElement = input->closedShadowRoot()->getElementById(ShadowElementNames::sliderTrack()); if (!input->layoutObject() || !layoutBox() || !trackElement->layoutBox()) return; LayoutPoint offset = roundedLayoutPoint(input->layoutObject()->absoluteToLocal(FloatPoint(point), UseTransforms)); bool isVertical = hasVerticalAppearance(input.get()); bool isLeftToRightDirection = layoutBox()->style()->isLeftToRightDirection(); LayoutUnit trackSize; LayoutUnit position; LayoutUnit currentPosition; // We need to calculate currentPosition from absolute points becaue the // renderer for this node is usually on a layer and layoutBox()->x() and // y() are unusable. // FIXME: This should probably respect transforms. LayoutPoint absoluteThumbOrigin = layoutBox()->absoluteBoundingBoxRectIgnoringTransforms().location(); LayoutPoint absoluteSliderContentOrigin = roundedLayoutPoint(input->layoutObject()->localToAbsolute()); IntRect trackBoundingBox = trackElement->layoutObject()->absoluteBoundingBoxRectIgnoringTransforms(); IntRect inputBoundingBox = input->layoutObject()->absoluteBoundingBoxRectIgnoringTransforms(); if (isVertical) { trackSize = trackElement->layoutBox()->contentHeight() - layoutBox()->size().height(); position = offset.y() - layoutBox()->size().height() / 2 - trackBoundingBox.y() + inputBoundingBox.y() - layoutBox()->marginBottom(); currentPosition = absoluteThumbOrigin.y() - absoluteSliderContentOrigin.y(); } else { trackSize = trackElement->layoutBox()->contentWidth() - layoutBox()->size().width(); position = offset.x() - layoutBox()->size().width() / 2 - trackBoundingBox.x() + inputBoundingBox.x(); position -= isLeftToRightDirection ? layoutBox()->marginLeft() : layoutBox()->marginRight(); currentPosition = absoluteThumbOrigin.x() - absoluteSliderContentOrigin.x(); } position = std::max<LayoutUnit>(0, std::min(position, trackSize)); const Decimal ratio = Decimal::fromDouble(static_cast<double>(position) / trackSize); const Decimal fraction = isVertical || !isLeftToRightDirection ? Decimal(1) - ratio : ratio; StepRange stepRange(input->createStepRange(RejectAny)); Decimal value = stepRange.clampValue(stepRange.valueFromProportion(fraction)); Decimal closest = input->findClosestTickMarkValue(value); if (closest.isFinite()) { double closestFraction = stepRange.proportionFromValue(closest).toDouble(); double closestRatio = isVertical || !isLeftToRightDirection ? 1.0 - closestFraction : closestFraction; LayoutUnit closestPosition = trackSize * closestRatio; const LayoutUnit snappingThreshold = 5; if ((closestPosition - position).abs() <= snappingThreshold) value = closest; } String valueString = serializeForNumberType(value); if (valueString == input->value()) return; // FIXME: This is no longer being set from renderer. Consider updating the method name. input->setValueFromRenderer(valueString); if (layoutObject()) layoutObject()->setNeedsLayoutAndFullPaintInvalidation(LayoutInvalidationReason::SliderValueChanged); }
void RangeInputType::handleKeydownEvent(KeyboardEvent* event) { if (element().isDisabledOrReadOnly()) return; const String& key = event->keyIdentifier(); const Decimal current = parseToNumberOrNaN(element().value()); ASSERT(current.isFinite()); StepRange stepRange(createStepRange(RejectAny)); // FIXME: We can't use stepUp() for the step value "any". So, we increase // or decrease the value by 1/100 of the value range. Is it reasonable? const Decimal step = equalLettersIgnoringASCIICase(element().fastGetAttribute(stepAttr), "any") ? (stepRange.maximum() - stepRange.minimum()) / 100 : stepRange.step(); const Decimal bigStep = std::max((stepRange.maximum() - stepRange.minimum()) / 10, step); bool isVertical = false; if (element().renderer()) { ControlPart part = element().renderer()->style().appearance(); isVertical = part == SliderVerticalPart || part == MediaVolumeSliderPart; } Decimal newValue; if (key == "Up") newValue = current + step; else if (key == "Down") newValue = current - step; else if (key == "Left") newValue = isVertical ? current + step : current - step; else if (key == "Right") newValue = isVertical ? current - step : current + step; else if (key == "PageUp") newValue = current + bigStep; else if (key == "PageDown") newValue = current - bigStep; else if (key == "Home") newValue = isVertical ? stepRange.maximum() : stepRange.minimum(); else if (key == "End") newValue = isVertical ? stepRange.minimum() : stepRange.maximum(); else return; // Did not match any key binding. newValue = stepRange.clampValue(newValue); if (newValue != current) { EventQueueScope scope; setValueAsDecimal(newValue, DispatchInputAndChangeEvent, IGNORE_EXCEPTION); if (AXObjectCache* cache = element().document().existingAXObjectCache()) cache->postNotification(&element(), AXObjectCache::AXValueChanged); } event->setDefaultHandled(); }
Decimal multiply(const Decimal& another){ Decimal product; product.length=length+another.length-1; product.scale=scale+another.scale; for(int i=0;i<length;i++) for(int j=0;j<another.length;j++) product.digits[i+j]+=digits[i]*another.digits[j]; product.normalize(); return product; }
void CouchbaseEmbedFunctionContext::getDecimalResult(Decimal &value) { auto text = nextResultScalar(); if (text && *text) value.setString(rtlUtf8Length(strlen(text), text), text); else { NullFieldProcessor p(NULL); value.set(p.decimalResult); } }
Decimal Decimal::op_add(const Decimal rhs) const { TTInt rett; rett = this->GetTTInt(); rett.Add(rhs.GetTTInt()); Decimal ret; ret.SetTTInt(rett); return ret; }
Decimal Decimal::op_subtract(const Decimal rhs) const { TTInt rett; rett = this->GetTTInt(); rett.Sub(rhs.GetTTInt()); Decimal ret; ret.SetTTInt(rett); return ret; }
static PassRefPtr<TypeBuilder::Animation::KeyframeStyle> buildObjectForStringKeyframe(const StringKeyframe* keyframe) { Decimal decimal = Decimal::fromDouble(keyframe->offset() * 100); String offset = decimal.toString(); offset.append("%"); RefPtr<TypeBuilder::Animation::KeyframeStyle> keyframeObject = TypeBuilder::Animation::KeyframeStyle::create() .setOffset(offset) .setEasing(keyframe->easing().toString()); return keyframeObject.release(); }
String BaseDateAndTimeInputType::serializeWithComponents(const DateComponents& date) const { Decimal step; if (!element()->getAllowedValueStep(&step)) return date.toString(); if (step.remainder(msecPerMinute).isZero()) return date.toString(DateComponents::None); if (step.remainder(msecPerSecond).isZero()) return date.toString(DateComponents::Second); return date.toString(DateComponents::Millisecond); }
bool InputType::stepMismatch(const String& value) const { if (!isSteppable()) return false; const Decimal numericValue = parseToNumberOrNaN(value); if (!numericValue.isFinite()) return false; return createStepRange(RejectAny).stepMismatch(numericValue); }
bool InputType::rangeOverflow(const String& value) const { if (!isSteppable()) return false; const Decimal numericValue = parseToNumberOrNaN(value); if (!numericValue.isFinite()) return false; return numericValue > createStepRange(RejectAny).maximum(); }
virtual void processUDecimal(const void *value, unsigned digits, unsigned precision, const RtlFieldInfo * field) { Decimal val; size32_t bytes; char *data; val.setUDecimal(digits, precision, value); val.getStringX(bytes, data); MYSQL_BIND &bindInfo = createBindBuffer(MYSQL_TYPE_STRING, 0); bindInfo.buffer = data; bindInfo.buffer_length = bytes; bindInfo.length = &bindInfo.buffer_length; }
bool InputType::isOutOfRange(const String& value) const { if (!isSteppable()) return false; const Decimal numericValue = parseToNumberOrNaN(value); if (!numericValue.isFinite()) return true; StepRange stepRange(createStepRange(RejectAny)); return numericValue < stepRange.minimum() || numericValue > stepRange.maximum(); }
Decimal Decimal::op_multiply(const Decimal rhs) const { TTLInt rett; rett = this->GetTTInt(); rett *= rhs.GetTTInt(); rett /= Decimal::kMaxScaleFactor; Decimal ret; ret.SetTTInt(rett); return ret; }
Decimal Decimal::op_divide(const Decimal rhs) const { TTLInt rett; rett = this->GetTTInt(); rett *= Decimal::kMaxScaleFactor; rett /= rhs.GetTTInt(); Decimal ret; ret.SetTTInt(rett); return ret; }
void main() { // Define an array of byte values. array<Byte>^ values = { Byte::MinValue, Byte::MaxValue, 0x3F, 123, 200 }; // Convert each value to a Decimal. for each (Byte value in values) { Decimal decValue = value; Console::WriteLine("{0} ({1}) --> {2} ({3})", value, value.GetType()->Name, decValue, decValue.GetType()->Name); }