當前位置: 首頁>>代碼示例>>C++>>正文


C++ Fraction函數代碼示例

本文整理匯總了C++中Fraction函數的典型用法代碼示例。如果您正苦於以下問題:C++ Fraction函數的具體用法?C++ Fraction怎麽用?C++ Fraction使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Fraction函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: Q_ASSERT

Fraction XmlReader::readFraction()
      {
      Q_ASSERT(tokenType() == QXmlStreamReader::StartElement);
      int z = attribute("z", "0").toInt();
      int n = attribute("n", "1").toInt();
      const QString& s(readElementText());
      if (!s.isEmpty()) {
            int i = s.indexOf('/');
            if (i == -1)
                  qFatal("illegal fraction <%s>", qPrintable(s));
            else {
                  z = s.left(i).toInt();
                  n = s.mid(i+1).toInt();
                  }
            }
      return Fraction(z, n);
      }
開發者ID:Angeldude,項目名稱:MuseScore,代碼行數:17,代碼來源:xml.cpp

示例2: Fraction

Polynom& Polynom::operator -= (const Polynom& _another) {
	Polynom result;
	result.a.resize(max(pow(), _another.pow()) + 1, Fraction(0, 1)); //0 instead of Fraction(0,1) gives really strange results

	for(int i = 0; i <= pow(); i++) {
		result.a[i] += a[i];
	}
	for(int i = 0; i <= _another.pow(); i++) {
		result.a[i] -= _another.a[i];
	}

	a = result.a;

	simplify();

	return *this;
}
開發者ID:HPotter,項目名稱:ProgrammingLessons,代碼行數:17,代碼來源:polynom.cpp

示例3: toDurationList

std::vector<TDuration> toDurationList(Fraction l, bool useDots, int maxDots, bool printRestRemains)
      {
      std::vector<TDuration> dList;
      dList.reserve(8);

      if (useDots) {
            for (TDuration d = TDuration(TDuration::DurationType::V_LONG); d.isValid() && (l.numerator() != 0);) {
                  int dots = maxDots;
                  for ( ; dots > 0; --dots) {
                        d.setDots(dots);
                        Fraction ff = l - d.fraction();
                        if (ff.numerator() >= 0) {
                              dList.push_back(d);
                              l -= d.fraction();
                              break;
                              }
                        }
                  if (dots > 0)
                        continue;
                  d.setDots(0);
                  Fraction ff = l - d.fraction();
                  if (ff.numerator() < 0)
                        d = d.shift(1);
                  else {
                        dList.push_back(d);
                        l -= d.fraction();
                        }
                  }
            }
      else {
            for (TDuration d = TDuration(TDuration::DurationType::V_LONG); d.isValid() && (l.numerator() != 0);) {
                  Fraction ff(l - d.fraction());
                  if (ff.numerator() < 0) {
                        d = d.shift(1);
                        continue;
                        }
                  l -= d.fraction();
                  dList.push_back(d);
                  }
            }
      if (printRestRemains && l != Fraction())
            qDebug("toDurationList:: rest remains %d/%d", l.numerator(), l.denominator());

      return dList;
      }
開發者ID:NupurMalpani,項目名稱:MuseScore,代碼行數:45,代碼來源:durationtype.cpp

示例4: toDurationList

QList<TDuration> toDurationList(Fraction l, bool useDottedValues)
      {
      QList<TDuration> dList;
      if (useDottedValues) {
            for (TDuration d = TDuration(TDuration::V_LONG); d.isValid() && (l.numerator() != 0);) {
                  d.setDots(2);
                  Fraction ff(l - d.fraction());
                  if (ff.numerator() >= 0) {
                        dList.append(d);
                        l -= d.fraction();
                        continue;
                        }
                  d.setDots(1);
                  ff = l - d.fraction();
                  if (ff.numerator() >= 0) {
                        dList.append(d);
                        l -= d.fraction();
                        continue;
                        }
                  d.setDots(0);
                  ff = l - d.fraction();
                  if (ff.numerator() < 0) {
                        d = d.shift(1);
                        }
                  else {
                        l -= d.fraction();
                        dList.append(d);
                        }
                  }
            }
      else {
            for (TDuration d = TDuration(TDuration::V_LONG); d.isValid() && (l.numerator() != 0);) {
                  Fraction ff(l - d.fraction());
                  if (ff.numerator() < 0) {
                        d = d.shift(1);
                        continue;
                        }
                  l -= d.fraction();
                  dList.append(d);
                  }
            }
      if (l != Fraction())
            qDebug("toDurationList:: rest remains %d/%d", l.numerator(), l.denominator());
      return dList;
      }
開發者ID:aeliot,項目名稱:MuseScore,代碼行數:45,代碼來源:durationtype.cpp

示例5: TimeSig

void TimeDialog::addClicked()
      {
      TimeSig* ts = new TimeSig(gscore);
      ts->setSig(Fraction(zNominal->value(), denominator()));
      ts->setGroups(groups->groups());

      // check for special text
      if ((QString("%1").arg(zNominal->value()) != zText->text())
         || (QString("%1").arg(denominator()) != nText->text())) {
            ts->setNumeratorString(zText->text());
            ts->setDenominatorString(nText->text());
            }
      // extend palette:
      sp->append(ts, "");
      _dirty = true;
      sp->updateGeometry();
      _timePalette->adjustSize();
      }
開發者ID:CafeCat,項目名稱:MuseScore,代碼行數:18,代碼來源:timedialog.cpp

示例6: gst_qt_quick2_video_sink_set_property

static void
gst_qt_quick2_video_sink_set_property (GObject *object,
                                       guint property_id,
                                       const GValue *value,
                                       GParamSpec *pspec)
{
    GstQtQuick2VideoSink *self = GST_QT_QUICK2_VIDEO_SINK (object);

    switch (property_id) {
    case PROP_PIXEL_ASPECT_RATIO:
      {
        GValue tmp;
        std::memset(&tmp, 0, sizeof(GValue));
        g_value_init(&tmp, GST_TYPE_FRACTION);
        if (g_value_transform(value, &tmp)) {
            int n = gst_value_get_fraction_numerator(&tmp);
            int d = gst_value_get_fraction_denominator(&tmp);
            self->priv->delegate->setPixelAspectRatio(Fraction(n, d));
        } else {
            GST_WARNING_OBJECT(object, "Could not transform string to aspect ratio");
        }
        g_value_unset(&tmp);
        break;
      }
    case PROP_FORCE_ASPECT_RATIO:
        self->priv->delegate->setForceAspectRatio(g_value_get_boolean(value));
        break;
    case PROP_CONTRAST:
        self->priv->delegate->setContrast(g_value_get_int(value));
        break;
    case PROP_BRIGHTNESS:
        self->priv->delegate->setBrightness(g_value_get_int(value));
        break;
    case PROP_HUE:
        self->priv->delegate->setHue(g_value_get_int(value));
        break;
    case PROP_SATURATION:
        self->priv->delegate->setSaturation(g_value_get_int(value));
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
        break;
    }
}
開發者ID:dejunk,項目名稱:gstreamer,代碼行數:44,代碼來源:gstqtquick2videosink.cpp

示例7: toDurationList

QList<TDuration> toDurationList(Fraction l, bool useDots, int maxDots)
      {
      QList<TDuration> dList;
      if (useDots) {
            for (TDuration d = TDuration(TDuration::V_LONG); d.isValid() && (l.numerator() != 0);) {
                  int dots = maxDots;
                  for ( ; dots > 0; --dots) {
                        d.setDots(dots);
                        Fraction ff = l - d.fraction();
                        if (ff.numerator() >= 0) {
                              dList.append(d);
                              l -= d.fraction();
                              break;
                              }
                        }
                  if (dots > 0)
                        continue;
                  d.setDots(0);
                  Fraction ff = l - d.fraction();
                  if (ff.numerator() < 0) {
                        d = d.shift(1);
                        }
                  else {
                        dList.append(d);
                        l -= d.fraction();
                        }
                  }
            }
      else {
            for (TDuration d = TDuration(TDuration::V_LONG); d.isValid() && (l.numerator() != 0);) {
                  Fraction ff(l - d.fraction());
                  if (ff.numerator() < 0) {
                        d = d.shift(1);
                        continue;
                        }
                  l -= d.fraction();
                  dList.append(d);
                  }
            }
      if (l != Fraction())
            qDebug("toDurationList:: rest remains %d/%d", l.numerator(), l.denominator());
      return dList;
      }
開發者ID:33akash,項目名稱:MuseScore,代碼行數:43,代碼來源:durationtype.cpp

示例8: main

int main()
{
    while (true) {
        scanf("%d", &n);
        if (n == 0) break;

        Fraction f(1, n);
        Fraction s(1, n);

        for (int i = 2, d = n - 1; i <= n; ++i, --d) {
            f = s * Fraction(1, d);
            s = s + f;
        }

        printf("%d/%d\n", f.p, f.q);
    }

    return 0;
}
開發者ID:pin3da,項目名稱:pc-code,代碼行數:19,代碼來源:airplane.cpp

示例9: SYSTEMTIME

CNtpTime::operator SYSTEMTIME() const
{
//	Currently this function only operates correctly in
//	the 1900- 2036 primary epoch defined by NTP
	SYSTEMTIME st;
	DWORD s	= Seconds();
	st.wSecond	= (WORD)( s % 60 );
	s	/= 60;
	st.wMinute	= (WORD)( s % 60 );
	s	/= 60;
	st.wHour	= (WORD)( s % 24 );
	s	/= 24;
	long JD	= s + JAN_1ST_1900;
	st.wDayOfWeek	= (WORD)( ( JD + 1 ) % 7 );
	GetGregorianDate( JD, st.wYear, st.wMonth, st.wDay );
	st.wMilliseconds	= NtpFractionToMs( Fraction() );

	return st;
}
開發者ID:KerwinMa,項目名稱:AerothFlyffSource,代碼行數:19,代碼來源:Sntp.cpp

示例10: Fraction

void kcs::Row::doReverseEliminate(Row & two){
    int second=0;
    Fraction** twoNums =two.getNumbers();
     for(int i=0;i<length;i++){
        if(!twoNums[i]->isEqual(0)){

            second=i;
            break;
        }
    }

    Fraction theMain = Fraction(numbers[second]->getNumerator(),numbers[second]->getDnumerator());

    for(int i=second;i<length;i++){
        Fraction tmp =(twoNums[i]->doMultiply(theMain));
        numbers[i] ->doMinus(  tmp   );
    }


}
開發者ID:JackSie,項目名稱:SomeHomeworkCode-sophomore,代碼行數:20,代碼來源:Row.cpp

示例11: switch

void FractionCalculator::compute(void)
{
	switch(this->operation)
	{
		case '+':
			this->result = this->f1 + this->f2;
			break;
		case '-':
			this->result = this->f1 - this->f2;
			break;
		case '*':
			this->result = this->f1 * this->f2;
			break;
		case '/':
			this->result = this->f1 / this->f2;
			break;
		default:
			this->result = Fraction();	// set to a Fraction(0) if invalid operation
	}
	return;
}
開發者ID:pyridoxus,項目名稱:csc125Project3,代碼行數:21,代碼來源:FractionCalculator.cpp

示例12: writeProperty

void TimeSig::write(XmlWriter& xml) const
      {
      xml.stag("TimeSig");
      writeProperty(xml, P_ID::TIMESIG_TYPE);
      Element::writeProperties(xml);

      xml.tag("sigN",  _sig.numerator());
      xml.tag("sigD",  _sig.denominator());
      if (stretch() != Fraction(1,1)) {
            xml.tag("stretchN", stretch().numerator());
            xml.tag("stretchD", stretch().denominator());
            }
      writeProperty(xml, P_ID::NUMERATOR_STRING);
      writeProperty(xml, P_ID::DENOMINATOR_STRING);
      if (!_groups.empty())
            _groups.write(xml);
      writeProperty(xml, P_ID::SHOW_COURTESY);
      writeProperty(xml, P_ID::SCALE);

      xml.etag();
      }
開發者ID:akdor1154,項目名稱:MuseScore,代碼行數:21,代碼來源:timesig.cpp

示例13: switch

SymId Rest::getSymbol(TDuration::DurationType type, int line, int lines, int* yoffset)
      {
      *yoffset = 2;
      switch(type) {
            case TDuration::DurationType::V_LONG:
                  return SymId::restLonga;
            case TDuration::DurationType::V_BREVE:
                  return SymId::restDoubleWhole;
            case TDuration::DurationType::V_MEASURE:
                  if (duration() >= Fraction(2, 1))
                        return SymId::restDoubleWhole;
                  // fall trough
            case TDuration::DurationType::V_WHOLE:
                  *yoffset = 1;
                  return (line <= -2 || line >= (lines - 1)) ? SymId::restWholeLegerLine : SymId::restWhole;
            case TDuration::DurationType::V_HALF:
                  return (line <= -3 || line >= (lines - 2)) ? SymId::restHalfLegerLine : SymId::restHalf;
            case TDuration::DurationType::V_QUARTER:
                  return SymId::restQuarter;
            case TDuration::DurationType::V_EIGHT:
                  return SymId::rest8th;
            case TDuration::DurationType::V_16TH:
                  return SymId::rest16th;
            case TDuration::DurationType::V_32ND:
                  return SymId::rest32nd;
            case TDuration::DurationType::V_64TH:
                  return SymId::rest64th;
            case TDuration::DurationType::V_128TH:
                  return SymId::rest128th;
            case TDuration::DurationType::V_256TH:
                  return SymId::rest256th;
            case TDuration::DurationType::V_512TH:
                  return SymId::rest512th;
            case TDuration::DurationType::V_1024TH:
                  return SymId::rest1024th;
            default:
                  qDebug("unknown rest type %d", type);
                  return SymId::restQuarter;
            }
      }
開發者ID:Igevorse,項目名稱:MuseScore,代碼行數:40,代碼來源:rest.cpp

示例14: applySwing

void SwingDetector::applySwing()
      {
      if (elements.size() != 2 && elements.size() != 3)
            return;

      Tuplet *tuplet = nullptr;
      for (ChordRest *el: elements) {
            el->setDurationType(TDuration::DurationType::V_EIGHTH);
            el->setTicks(Fraction(1, 8));
            el->setDots(0);
            if (el->tuplet()) {
                  if (!tuplet)
                        tuplet = el->tuplet();
                  tuplet->remove(el);
                  el->setTuplet(nullptr);
                  }
            }

      const ChordRest *first = elements.front();
      const int startTick = first->segment()->tick().ticks();
      ChordRest *last = elements.back();
      last->segment()->remove(last);
      Segment *s = last->measure()->getSegment(SegmentType::ChordRest, Fraction::fromTicks(startTick + MScore::division / 2));
      s->add(last);

      if (elements.size() == 3) {
                  // remove central rest
            ChordRest *cr = elements[1];
            cr->score()->removeElement(cr);
            delete cr;
            }

      if (tuplet) {
                  // delete tuplet
            delete tuplet;
            tuplet = nullptr;
            }
      if (!swingApplied)
            swingApplied = true;
      }
開發者ID:Jojo-Schmitz,項目名稱:MuseScore,代碼行數:40,代碼來源:importmidi_swing.cpp

示例15: switch

int Rest::getSymbol(TDuration::DurationType type, int line, int lines, int* yoffset)
      {
      *yoffset = 2;
      switch(type) {
            case TDuration::V_LONG:
                  return longarestSym;
            case TDuration::V_BREVE:
                  return breverestSym;
            case TDuration::V_MEASURE:
                  if (duration() >= Fraction(2, 1))
                        return breverestSym;
                  // fall trough
            case TDuration::V_WHOLE:
                  *yoffset = 1;
                  return (line <= -2 || line >= (lines - 1)) ? outsidewholerestSym : wholerestSym;
            case TDuration::V_HALF:
                  return (line <= -3 || line >= (lines - 2)) ? outsidehalfrestSym : halfrestSym;
            case TDuration::V_QUARTER:
                  return rest4Sym;
            case TDuration::V_EIGHT:
                  return rest8Sym;
            case TDuration::V_16TH:
                  return rest16Sym;
            case TDuration::V_32ND:
                  return rest32Sym;
            case TDuration::V_64TH:
                  return rest64Sym;
            case TDuration::V_128TH:
                  return rest128Sym;
            case TDuration::V_256TH:
                  qDebug("Rest: no symbol for 1/256");
                  return rest128Sym;
            default:
                  qDebug("unknown rest type %d", type);
                  return rest4Sym;
            }
      }
開發者ID:ccorbell,項目名稱:MuseScore,代碼行數:37,代碼來源:rest.cpp


注:本文中的Fraction函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。