本文整理汇总了C++中Rational函数的典型用法代码示例。如果您正苦于以下问题:C++ Rational函数的具体用法?C++ Rational怎么用?C++ Rational使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Rational函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: Rational
Rational operator*(Rational num1, Rational num2)
{
int c = num1.getB() * num2.getB();
int d = num1.getA() * num2.getA();
return Rational(d, c);
}
开发者ID:keirsan,项目名称:TeamFirstFpmiLaba,代码行数:6,代码来源:Rational.cpp
示例2: Rational
Rational Rational::Inverse() {
if(num == 0)
return Rational(num, den);
else
return Rational(den, num);
}
开发者ID:MatthewMcGonagle,项目名称:QuadraticFieldExtension,代码行数:6,代码来源:QuadraticField.cpp
示例3: opposite
Rational opposite() const
{
return Rational(-numerator, denominator);
}
开发者ID:templateaholic10,项目名称:testrepo,代码行数:4,代码来源:crtp.hpp
示例4: Rational
bool Rational::operator>(int right) const {
return *this > Rational(right, 1);
}
开发者ID:AdamRi,项目名称:scummvm-pink,代码行数:3,代码来源:rational.cpp
示例5: if
bool QuadraticField::FindSqrt(std::vector<Rational> root_) {
if(root_.size() != degree)
return false;
else if(degree==2) {
// We look for a square root of the form a+b*R^(1/2) where a,b rational.
// For the notes, we are finding the square root of X+Y*R^(1/2)
// so that X = root_[0] and Y = root_[1].
Rational newroot(1,1), newrootB(1,1); // Extra variables that will be necessary later
if(root_[1].IsZero()) {
// The case of finding square root of X
// Solve a^2 + R b^2 = X and 2ab = 0
// The case that a=0
// Look at b = (X/R)^(1/2)
newroot = root_[0]*Root[0].Inverse();
if(newroot.FindSqrt()) {
Result[0] = Rational(0,1);
Result[1] = newroot.GetSqrt();
return true;
}
// The case that b=0
// Look at a = X^(1/2)
newroot = root_[0];
if(newroot.FindSqrt()) {
Result[0] = newroot.GetSqrt();
Result[1] = Rational(0,1);
return true;
}
// Neither Case Works, so there is no square root
return false;
}
else {
// Looking at the hardest case of Y non-zero
// Solve a^2 + R b^2 = X and 2ab = Y
// Now know that a and b both are non-zero,
// So it is safe to substitute b = Y/2a into the
// first equation.
// So we must solve a^2 + (R/4) Y^2/a^2 = X
// equivalent to a^4 - X a^2 + (R/4) Y^2 = 0.
// Need to find a in Q satisfying quartic polynomial.
// Quadratic Formula tells us a^2 is in Q iff
// (X^2 - R Y^2)^(1/2) is in Q. First check this.
newroot = root_[0]*root_[0] - Root[0]*root_[1]*root_[1];
if(newroot.FindSqrt()) {
// Know that a^2 is in the Q. Need to check square root
// of either positive or negative root to see if any a
// is in the field
newroot = newroot.GetSqrt();
// Check the plus root
newrootB = (root_[0]+newroot)*Rational(1,2);
if(newrootB.FindSqrt()) {
Result[0] = newrootB.GetSqrt();
Result[1] = root_[1]*Rational(1,2)*Result[0].Inverse();
return true;
}
//Check the minus root
newrootB = (root_[0]-newroot)*Rational(1,2);
if(newrootB.FindSqrt()) {
Result[0] = newrootB.GetSqrt();
Result[1] = root_[1]*Rational(1,2)*Result[0].Inverse();
return true;
}
// Neither plus/minus root has a root in Q. So there is no rational root
return false;
}
else
return false;
}
}
else {
return false;
}
}
开发者ID:MatthewMcGonagle,项目名称:QuadraticFieldExtension,代码行数:84,代码来源:QuadraticField.cpp
示例6: Rational
Rational Rational::operator-() const
{
return Rational(-numerator, denominator, no_normalise_tag());
}
开发者ID:FrancisRussell,项目名称:excafe,代码行数:4,代码来源:rational.cpp
示例7: setEditRate
void WaveAudioEssenceReader::setEditRate(const Rational& rate)
{
_editRate = rate;
//WaveAudioEssenceDescriptor* waed =
// dynamic_cast<WaveAudioEssenceDescriptor*>(_descriptor);
//if (waed == 0)
//{
// /// \todo report error
// return;
//}
//waed->setSampleRate(rate);
// A call to set the edit rate will also set the container duration.
// Calculate frame and buffer sizes
_baseSampleCount = 0; // reset so we can detect error
if (rate == Rational(30000, 1001))
{
if (_fmtChunk->nSamplesPerSec == 48000)
{
_baseSampleCount = 1600;
_additionalSampleCounts = 5;
_additionalSampleCount[0] = 2;
_additionalSampleCount[1] = 1;
_additionalSampleCount[2] = 2;
_additionalSampleCount[3] = 1;
_additionalSampleCount[4] = 2;
}
/// \todo warn if audio data isn't 48kHz
}
else
{
_baseSampleCount = (UInt32)(
_fmtChunk->nSamplesPerSec *
(UInt64) rate.getDenominator() /
(UInt64) rate.getNumerator());
_additionalSampleCounts = 0;
}
_combinedDataLength = 0;
if (_additionalSampleCounts > 0)
{
// Calculate the average buffer size
for (UInt32 i = 0; i < _additionalSampleCounts; ++i)
{
_combinedDataLength +=
(_baseSampleCount + _additionalSampleCount[i]) *
(_fmtChunk->wBitsPerSample / 8) *
_fmtChunk->nChannels;
}
}
else
{
_combinedDataLength =
_baseSampleCount *
(_fmtChunk->wBitsPerSample / 8) *
_fmtChunk->nChannels;
}
if (_baseSampleCount == 0 || _combinedDataLength == 0)
{
// We've failed to determine the size of an edit unit
error(ESS_ERROR_FailedToDetermineFrameSize);
return;
}
// Update the duration for the essence descriptor
if (_additionalSampleCounts > 0)
{
Length duration = ((_dataLength * _additionalSampleCounts) / _combinedDataLength);
// we have to do the rounding manually as ceil() takes a double
// and VC6 can't handle unsigned int64 to double...
Length rem = (_dataLength * _additionalSampleCounts) % _combinedDataLength;
if (rem != 0)
duration++; // round up
//waed->setContainerDuration(duration);
_containerDuration = duration;
}
else
{
Length duration = _dataLength / _combinedDataLength;
// we have to do the rounding manually as ceil() takes a double
// and VC6 can't handle unsigned int64 to double...
Length rem = _dataLength % _combinedDataLength;
if (rem != 0)
duration++; // round up
//waed->setContainerDuration(duration);
_containerDuration = duration;
}
}
开发者ID:dcsch,项目名称:asiotest,代码行数:96,代码来源:WaveAudioEssenceReader.cpp
示例8: Rational
Expr Expr::operator-() const
{
return Sum::rational_multiple(*this, Rational(-1)).simplify();
}
开发者ID:FrancisRussell,项目名称:excafe,代码行数:4,代码来源:expr.cpp
示例9: Rational
Rational Xmpdatum::toRational(long n) const
{
return p_->value_.get() == 0 ? Rational(-1, 1) : p_->value_->toRational(n);
}
开发者ID:dtbinh,项目名称:dviz,代码行数:4,代码来源:xmp.cpp
示例10:
VideoFormat::VideoFormat(AVCodecContext * ctx) {
_width=ctx->width;
_height=ctx->height;
_framerate=Rational(ctx->time_base.num,ctx->time_base.den);
_type=FORMAT_VIDEO;
}
开发者ID:psychobob666,项目名称:MediaEncodingCluster,代码行数:6,代码来源:VideoFormat.cpp
示例11: Point
Point(const Rational& x = Rational(), const Rational& y = Rational()) : x_(x), y_(y) {
}
开发者ID:DrSunglasses,项目名称:zcta,代码行数:2,代码来源:Point.hpp
示例12: pow
Rational operator^(Rational num1, int power)
{
int c = pow(num1.getB(), power);
int d = pow(num1.getA(), power);
return Rational(d, c);
}
开发者ID:keirsan,项目名称:TeamFirstFpmiLaba,代码行数:6,代码来源:Rational.cpp
示例13: Rational
Rational & operator /=( int i ) {
(*this) /= Rational(i);
return * this ;
}
开发者ID:devtype-blogspot-com,项目名称:CPP-Examples,代码行数:4,代码来源:main.cpp
示例14: BipartiteMatching
void Broder86::computeNeighbours(const BipartiteMatching& s,
boost::unordered_map<BipartiteMatching, Rational>& neighbors) const {
// Variables
const int n = g.getNumberOfNodes();
const int k = s.k;
int u, v;
BipartiteMatching s2;
edgelist edges;
neighbors.clear();
// Implementierung der Transitionen nach Vorlage JS89
// Gehe über jede Kante
g.getEdges(edges);
//std::cout << "compute neighbors for s=" << s << std::endl;
// Für jede Wahl einer Kante e=(u,v) wird Transition konstruiert
for (typename edgelist::iterator it = edges.begin(); it != edges.end();
++it) {
u = it->first;
v = it->second;
// create new state as copy of old one
s2 = BipartiteMatching(s);
// Transition 1
if (2 * k == n && s.mates[u] == v) {
// remove edge (u,v)
s2.mates[u] = n;
s2.mates[v] = n;
s2.k = k - 1;
s2.unmatched[0] = u;
s2.unmatched[1] = v;
} else if (2 * k + 2 == n) {
// Transition 2
if (s.mates[u] == n && s.mates[v] == n) {
// add edge (u,v)
s2.mates[u] = v;
s2.mates[v] = u;
s2.k = k + 1;
s2.unmatched[0] = n;
s2.unmatched[1] = n;
}
// Transition 3a
else if (s.mates[u] != n && s.mates[v] == n) {
// remove edge (u, mate[u])
// add edge (u,v)
int w = s.mates[u];
s2.mates[w] = n;
s2.mates[u] = v;
s2.mates[v] = u;
// w=mate[u] (>= n/2) becomes unmatched node in bipartition group 1
s2.unmatched[1] = w;
}
// Transition 3b
else if (s.mates[u] == n && s.mates[v] != n) {
// remove edge (v, mate[v])
// add edge (u,v)
int w = s.mates[v];
s2.mates[w] = n;
s2.mates[u] = v;
s2.mates[v] = u;
// w=mate[v] (< n/2) becomes unmatched node in bipartition group 0
s2.unmatched[0] = w;
} else {
// stay in s
}
}
// sonst
else {
// Verbleibe im aktuellen Zustand
}
neighbors[s2] += Rational(1, edges.size());
//std::cout << std::endl;
}
}
开发者ID:hormigaloca,项目名称:marathon,代码行数:83,代码来源:matching_chain_JS89.cpp
示例15: levLoadData
//.........这里部分代码省略.........
debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_MKEEP_LIMBO, psNewLevel->apDataFiles[i]);
return false;
}
break;
default:
ASSERT(psNewLevel->type >= LDS_MULTI_TYPE_START, "Unexpected mission type");
debug(LOG_WZ, "default (MULTIPLAYER)");
if (!startMission(LDS_CAMSTART, psNewLevel->apDataFiles[i]))
{
debug(LOG_ERROR, "Failed startMission(%d, %s) (default)!", LDS_CAMSTART, psNewLevel->apDataFiles[i]);
return false;
}
break;
}
}
}
else if (psNewLevel->apDataFiles[i])
{
// load the data
debug(LOG_WZ, "Loading %s", psNewLevel->apDataFiles[i]);
if (!resLoad(psNewLevel->apDataFiles[i], i + CURRENT_DATAID))
{
debug(LOG_ERROR, "Failed resLoad(%s, %d) (default)!", psNewLevel->apDataFiles[i], i + CURRENT_DATAID);
return false;
}
}
}
if (bMultiPlayer)
{
// This calls resLoadFile("SMSG", "multiplay.txt"). Must be before loadMissionExtras, which calls loadSaveMessage, which calls getViewData.
loadMultiScripts();
}
if (pSaveName != nullptr)
{
//load MidMission Extras
if (!loadMissionExtras(pSaveName, psNewLevel->type))
{
debug(LOG_ERROR, "Failed loadMissionExtras(%s, %d)!", pSaveName, psNewLevel->type);
return false;
}
}
if (pSaveName != nullptr && saveType == GTYPE_SAVE_MIDMISSION)
{
//load script stuff
// load the event system state here for a save game
debug(LOG_SAVE, "Loading script system state");
if (!loadScriptState(pSaveName))
{
debug(LOG_ERROR, "Failed loadScriptState(%s)!", pSaveName);
return false;
}
}
if (!stageThreeInitialise())
{
debug(LOG_ERROR, "Failed stageThreeInitialise()!");
return false;
}
dataClearSaveFlag();
//this enables us to to start cam2/cam3 without going via a save game and get the extra droids
//in from the script-controlled Transporters
if (!pSaveName && psNewLevel->type == LDS_CAMSTART)
{
eventFireCallbackTrigger((TRIGGER_TYPE)CALL_NO_REINFORCEMENTS_LEFT);
}
//restore the level name for comparisons on next mission load up
if (psChangeLevel == nullptr)
{
psCurrLevel = psNewLevel;
}
else
{
psCurrLevel = psChangeLevel;
}
// Copy this info to be used by the crash handler for the dump file
char buf[256];
ssprintf(buf, "Current Level/map is %s", psCurrLevel->pName);
addDumpInfo(buf);
triggerEvent(TRIGGER_GAME_LOADED);
if (autogame_enabled())
{
gameTimeSetMod(Rational(500));
if (hostlaunch != 2) // tests will specify the AI manually
{
jsAutogameSpecific("multiplay/skirmish/semperfi.js", selectedPlayer);
}
}
return true;
}
开发者ID:ik3210,项目名称:warzone2100,代码行数:101,代码来源:levels.cpp
示例16: while
Tsubtitle* TsubtitleParserSSA::parse(Tstream &fd, int flags, REFERENCE_TIME start, REFERENCE_TIME stop)
{
/*
* Sub Station Alpha v4 (and v2?) scripts have 9 commas before subtitle
* other Sub Station Alpha scripts have only 8 commas before subtitle
* Reading the "ScriptType:" field is not reliable since many scripts appear
* w/o it
*
* http://www.scriptclub.org is a good place to find more examples
* http://www.eswat.demon.co.uk is where the SSA specs can be found
*/
wchar_t line0[this->LINE_LEN + 1];
wchar_t *line = line0;
int playResXscript = 0, playResYscript = 0;
while (fd.fgets(line, this->LINE_LEN)) {
#if 0
DPRINTF(L"%s", line);
#endif
lineID++;
if (line[0] == ';') {
continue;
}
wchar_t *cr = strrchr(line, '\n');
if (cr) {
*cr = '\0';
}
cr = strrchr(line, '\r');
if (cr) {
*cr = '\0';
}
if (strnicmp(line, L"[Script Info]", 13) == 0) {
inV4styles = 0;
inEvents = 0;
inInfo = 1;
} else if (inInfo && strnicmp(line, L"PlayResX:", 8) == 0) {
nmTextSubtitles::strToInt(line + 9, &playResXscript);
} else if (inInfo && strnicmp(line, L"PlayResY:", 8) == 0) {
nmTextSubtitles::strToInt(line + 9, &playResYscript);
} else if (inInfo && strnicmp(line, L"Timer:", 6) == 0) {
wchar_t *end;
double t = strtod(line + 7, &end);
if (*end == '\0' && t != 0) {
timer = Rational(t / 100.0, _I32_MAX);
}
} else if (inInfo && strnicmp(line, L"WrapStyle:", 9) == 0) {
nmTextSubtitles::strToInt(line + 10, &wrapStyle);
} else if (inInfo && strnicmp(line, L"ScaledBorderAndShadow:", 21) == 0) {
nmTextSubtitles::strToInt(line + 22, &scaleBorderAndShadow);
} else if (strnicmp(line, L"[V4 Styles]", 11) == 0) {
version = nmTextSubtitles::SSA;
inV4styles = 2;
inEvents = 0;
inInfo = 0;
} else if (strnicmp(line, L"[V4+ Styles]", 11) == 0) {
version = nmTextSubtitles::ASS;
inV4styles = 2;
inEvents = 0;
inInfo = 0;
} else if (strnicmp(line, L"[V4++ Styles]", 11) == 0) {
version = nmTextSubtitles::ASS2;
inV4styles = 2;
inEvents = 0;
inInfo = 0;
} else if (strnicmp(line, L"[Events]", 8) == 0) {
inV4styles = 0;
inEvents = 2;
inInfo = 0;
} else if (inV4styles == 2 && strnicmp(line, L"Format:", 7) == 0) {
strlwr(line);
strrmchar(line, L' ');
typedef std::vector<Tstrpart > Tparts;
Tparts fields;
const wchar_t *l = line + 7;
strtok(l, L",", fields);
styleFormat.clear();
for (Tparts::const_iterator f = fields.begin(); f != fields.end(); f++) {
if (strnicmp(f->first, L"name", 4) == 0) {
styleFormat.push_back(&TSSAstyle::name);
} else if (strnicmp(f->first, L"layer", 5) == 0) {
styleFormat.push_back(&TSSAstyle::layer);
} else if (strnicmp(f->first, L"fontname", 8) == 0) {
styleFormat.push_back(&TSSAstyle::fontname);
} else if (strnicmp(f->first, L"fontsize", 8) == 0) {
styleFormat.push_back(&TSSAstyle::fontsize);
} else if (strnicmp(f->first, L"primaryColour", 13) == 0) {
styleFormat.push_back(&TSSAstyle::primaryColour);
} else if (strnicmp(f->first, L"SecondaryColour", 15) == 0) {
styleFormat.push_back(&TSSAstyle::secondaryColour);
} else if (strnicmp(f->first, L"TertiaryColour", 14) == 0) {
styleFormat.push_back(&TSSAstyle::tertiaryColour);
} else if (strnicmp(f->first, L"OutlineColour", 13) == 0) {
styleFormat.push_back(&TSSAstyle::outlineColour);
} else if (strnicmp(f->first, L"BackColour", 10) == 0) {
styleFormat.push_back(&TSSAstyle::backgroundColour);
} else if (strnicmp(f->first, L"bold", 4) == 0) {
styleFormat.push_back(&TSSAstyle::bold);
} else if (strnicmp(f->first, L"italic", 6) == 0) {
styleFormat.push_back(&TSSAstyle::italic);
} else if (strnicmp(f->first, L"Underline", 9) == 0) {
styleFormat.push_back(&TSSAstyle::underline);
//.........这里部分代码省略.........
开发者ID:xinjiguaike,项目名称:ffdshow,代码行数:101,代码来源:TsubreaderMplayer.cpp
示例17: Rational
Rational StateGraph::getWeight(int i) const {
return Rational(1);
}
开发者ID:hormigaloca,项目名称:marathon,代码行数:3,代码来源:state_graph.cpp
示例18: inverse
Rational inverse() const
{
return Rational(denominator, numerator);
}
开发者ID:templateaholic10,项目名称:testrepo,代码行数:4,代码来源:crtp.hpp
示例19: LCM
Rational operator-(Rational num1, Rational num2)
{
int c = LCM(num1.getB(), num2.getB());
int d = (c / num1.getB())*num1.getA() - (c / num2.getB())*num2.getA();
return Rational(d, c);
}
开发者ID:keirsan,项目名称:TeamFirstFpmiLaba,代码行数:6,代码来源:Rational.cpp
注:本文中的Rational函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论