本文整理汇总了C++中Fraction函数的典型用法代码示例。如果您正苦于以下问题:C++ Fraction函数的具体用法?C++ Fraction怎么用?C++ Fraction使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fraction函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: min
Fraction SPTGSolver::nextEventPoint(){
cout << "====NextEventPoint===" << endl;
Fraction min(ifnty);
for (unsigned int state = 1; state < size; ++state){
// First we have to check if an epsilon can be found using the lambda transition
Fraction tempMin(ifnty);
if((*vals)[state][0] != lambdas[state][0] && lambdas[state][1] != (*vals)[state][1]){
tempMin = ((*vals)[state][0] - lambdas[state][0])/(lambdas[state][1] - (*vals)[state][1]);
if(tempMin < 0)
tempMin = ifnty;
if( time - tempMin < min)
min = tempMin;
}
for (unsigned int nextState = 0; nextState < size; ++nextState){
// Then we need to check if there is another epsilon that can be found using the other transitions
tempMin = Fraction(ifnty);
if(sptg->getTransition(state, nextState) != -1 && ((*vals)[state][0] != (*vals)[nextState][0] + sptg->getTransition(state, nextState)) &&
((*vals)[nextState][1] != (*vals)[state][1]))
{
tempMin = ((*vals)[state][0] - ((*vals)[nextState][0]+sptg->getTransition(state, nextState)))/((*vals)[nextState][1] - (*vals)[state][1]);
if(tempMin < 0)
tempMin = ifnty;
if(tempMin < min)
min = tempMin;
}
}
}
return min;
}
开发者ID:bryongloden,项目名称:PTGs,代码行数:36,代码来源:SPTGSolver.cpp
示例17: qDebug
void MsScWriter::doTriplet(Chord* cr, StartStop triplet)
{
qDebug() << "MsScWriter::doTriplet(" << triplet << ")"
;
if (triplet == ST_START) {
tuplet = new Tuplet(score);
tuplet->setTrack(0);
tuplet->setRatio(Fraction(3, 2));
tuplet->setTick(tick);
currentMeasure->add(tuplet);
}
else if (triplet == ST_STOP) {
if (tuplet) {
cr->setTuplet(tuplet);
tuplet->add(cr);
tuplet = 0;
}
else
qDebug("BWW::import: triplet stop without triplet start\n");
}
else if (triplet == ST_CONTINUE) {
if (!tuplet)
qDebug("BWW::import: triplet continue without triplet start\n");
}
else if (triplet == ST_NONE) {
if (tuplet)
qDebug("BWW::import: triplet none inside triplet\n");
}
else
qDebug("unknown triplet type %d\n", triplet);
if (tuplet) {
cr->setTuplet(tuplet);
tuplet->add(cr);
}
}
开发者ID:kcleung,项目名称:MuseScore,代码行数:36,代码来源:importbww.cpp
示例18: tr
Palette* MuseScore::newTimePalette()
{
struct TS {
int numerator;
int denominator;
TimeSigType type;
QString name;
};
TS tsList[] = {
{ 2, 4, TimeSigType::NORMAL, "2/4" },
{ 3, 4, TimeSigType::NORMAL, "3/4" },
{ 4, 4, TimeSigType::NORMAL, "4/4" },
{ 5, 4, TimeSigType::NORMAL, "5/4" },
{ 6, 4, TimeSigType::NORMAL, "6/4" },
{ 3, 8, TimeSigType::NORMAL, "3/8" },
{ 6, 8, TimeSigType::NORMAL, "6/8" },
{ 9, 8, TimeSigType::NORMAL, "9/8" },
{ 12, 8, TimeSigType::NORMAL, "12/8" },
{ 4, 4, TimeSigType::FOUR_FOUR, tr("4/4 common time") },
{ 2, 2, TimeSigType::ALLA_BREVE, tr("2/2 alla breve") }
};
Palette* sp = new Palette;
sp->setName(QT_TRANSLATE_NOOP("Palette", "Time Signatures"));
sp->setMag(.8);
sp->setGrid(42, 38);
for (unsigned i = 0; i < sizeof(tsList)/sizeof(*tsList); ++i) {
TimeSig* ts;
ts = new TimeSig(gscore);
ts->setSig(Fraction(tsList[i].numerator, tsList[i].denominator), tsList[i].type);
sp->append(ts, tsList[i].name);
}
return sp;
}
开发者ID:jasonmarkbeaton,项目名称:MuseScore,代码行数:36,代码来源:menus.cpp
示例19: init
void SPTGSolver::init(){
// Initialization of all vectors and variables used by the solver
size = sptg->getSize();
if(size != 0){
vals = new vector<vector<Fraction> >();
vals->push_back(vector<Fraction>());
(*vals)[0].push_back(Fraction(0));
(*vals)[0].push_back(Fraction(0));
strategies = new list<Strategy> ();
(*strategies).push_front(Strategy(size, time, false));
(*strategies).front().insert(0,0,0);
pathsLengths = new vector<unsigned int>();
pathsLengths->push_back(0);
lambdas.push_back(vector<Fraction>());
lambdas[0].push_back(Fraction(0));
lambdas[0].push_back(Fraction(0));
valueFcts = new vector<list<Point> >();
valueFcts->push_back(list<Point>());
// Fill the initial valors, strategies and the ensemble of states
for (unsigned int i = 1; i < size; ++i){
vals->push_back(vector<Fraction>());
(*vals)[i].push_back(Fraction(ifnty));
(*vals)[i].push_back(Fraction(0));
strategies->front().insert(i, -1, 0);
pathsLengths->push_back(0);
lambdas.push_back(vector<Fraction>());
lambdas[i].push_back(0);
lambdas[i].push_back(0);
valueFcts->push_back(list<Point>());
}
}
}
开发者ID:bryongloden,项目名称:PTGs,代码行数:41,代码来源:SPTGSolver.cpp
示例20: Fraction
Fraction Fraction:: operator * (const Fraction& other)
{
return Fraction(n*other.n, d*other.d);
}
开发者ID:EvgenyErmolovich,项目名称:Fraction,代码行数:4,代码来源:Fraction.cpp
注:本文中的Fraction函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论