Qt C++ Modulo Operator Failing [duplicate] - c++

This question already has answers here:
How to code a modulo (%) operator in C/C++/Obj-C that handles negative numbers
(16 answers)
Closed 6 years ago.
This is hopefully a really simple issue that I am overlooking. I am writing in C++ on Qt and I am working on ciphers. I have to use the %26 in order to get them working. I tested this: qDebug() << (6-18)%26; and according to the internet and math, it should produce me with the number 14, right? No. I get -12 which is what 6-18 is, so I don't know if the modulo isn't being applied of what. Any help is greatly appreciated.

You are right on this:
6-18 = -12
When I divide:
-12/26 = 0.46
With modulus = 4
I Hope this help you.

Related

what does this line of syntax mean in c++? [duplicate]

This question already has answers here:
'colon' and 'auto' in for loop c++? need some help understanding the syntax
(3 answers)
Closed 7 months ago.
this is a quick question, Im translating a program that's in C++ to C, and I saw this line of code,
for (int v : adj[u]) {
referenced in this article: link
and I am not really sure what it does. I tried googling it and got results for range based for loops in C++, but cannot find anything that has this exact syntax and what it means. Help would be much appreciated.
It's a very simple for loop that iterates over the elements of adj[u], going 1 by 1.

How to avoid NaN in C++ [duplicate]

This question already has answers here:
Checking if a double (or float) is NaN in C++
(21 answers)
Closed 4 years ago.
of course I know I should write better code which just not create NaN values.
But is there any casual method to avoid it. I mean something like:
if (!(floatNumber == NaN))
// do some stupid function
else
return;
But it doesn't work for me. I also tried floatNumber==null, but also no result.
Could you please help me?
To test whether a number is NaN, you can use the standard library function std::isnan.

How to increase the size of the int [duplicate]

This question already has answers here:
BigInteger in C?
(4 answers)
Closed 8 years ago.
I'm looking for a way so that I can get big numbers.
I want to calculate 38^n for n>4000
So is there any way to do this?
Kindly help me.
Look for a BigInt library like this one if the unsigned long long (64-bit integer) does not fit your needs.
Since 38^4000 =
13626567354997617056329313518572669871071170880583693359544272980041303981882434734538430960058767177295025923983566648755876881186325460368486197224167007060233768247052629486933889789012295518920202064862370213656621579461608833913900821509100620666110600996588831934295625624174881269739475099253543291971949351958375909705904924125614847402331728307491174234130043557765333856587852136763450074228033057943275251763474040244718003871446278851718437538753553972738188449864081284199350852720967506441771879828977604092893701331872025324453791540567000401652841385183230548306942426747811381344952202704995790135045091236882434632638273097622784399474964071260288840973524580293683712707126132726032058096115050808212994474874887195248086357178602097170972380906461711265125678088349923203375968414475787300592583696065816150079128755226670110739203817178406747936072376786260989121289233458431976862204647875012437031767751018704749869460607366074818959142212892198396374773980500350327658780222474479129859007194457457829138631699788091425513210781560184664312254850195910716334354324281366251167877851974205334475355985568256387781089509361002196647952275789359155111023451749451415734405096655278295174255960345304122475081165484445003142760913586534250626764015379905517010658444442626228678332925600616931303695695506161883152099899363859336729182377570281814058896416875807664402882868124355445335565905063833617714010822965856571393423962785717867701811630985000479945840574458836679738068978432208205049488474929993540051593774645379459275410621407737459680323962561140718740797900009352381301734433124145413190718954715078693891773766465543820020118333909425037946747920952112324716580163881088322718499979305631739834146130913408498900815005646996682256912339033205133816486824614258926495495812784036447453990264570960357479488597566262100857318557132063094971671138328081636423205300001440991841875093227157189180046979201235997836871115178473793331951908545162574227413951298558070125899512700390047047940487152449438682512124512374465180907633872133729735427824770312681013603101057078687642650433926086042263469811785972516780935001257979167301396531650578909144617556401661596286655000890845598227443074432224649650421444669509917690850588828467680365214374983571440413011029311538006314308009334022145676697106884765702897820392205002104976510511690662873648924905859206045090301538364495227369714240000327397892685270724477432224051710235161915341380166322505403047479921207485985826617144630062427543646106264207676267960138097995365712065699367252327692166917027162817512355112577817759333185119496357726652263574955692412766427791636621561003248143162088338810765811925034175243098253477183777981530119336600325069531470597361199726340530012493284901312472359938906404036536403970381273042347532022592036037374925652036435508211829648726060002645001171965651585268749073280713101532058063840348319740158848595441587678957522413199351039043113142029907129705744137232342011968704198807114940460676009450036521225461344010852618106239118154966331660057415602614793721826584529397251289749725656538096388399695143315928518563068548192735206544682378537520506418007926073285706849973274222076317373033059304200101911951067149937028894562722109537797411167898225856420348308410350603384055632474339567057703010340688068370821291318903177717596801407315734010878564418695310254546381520276678538725157608043309023441709322160712160377986536483006949768428055070012131321307517369398293559849470345086292046748890778373027131007888477361435703338650286281943866790521895536089587012314596482938225348353910513764482608946308253045592163757729525262326745493201953185303485264102739959029696399931572287438132772357749175882967079565029225741296582036140259021566923027054743911617278986639492312193679025969190891540930024189366778105054430929215092236023487686440492543667079519662985565417362492072592025055258819162704173072662013949276074302392094104918002731442385963738154377544394436144830710895941012427657480393526992952298836599116927265835864794883149357772532128926114623377650330127681469398680908197842808781573649462943403899309504315010053951097502630531047921616001572581816853481632903644705002543359747980637999901147726746920478281033260422246532219801930828506609799922586505464736354853965408705166237575268884142550705915838361403803760633861291439873689266312094985645627825768264532068068383940009347237832839084518620736293338032805140684318825609037052029320710069076942327055511619384729507413979366221173731875081583527606225142331708054058056316566268463694297799208229967327456031980737573803309723678915050699869715272912792497268191176053411510542893000088350086703903267923064151320399321810627158761446660416500169785103732189707448149719408203646028631800570100383545558186048239744484408082627734589940230907845416949939893008652775458505691974437891034384581573026445318317396853368414228897325531497788743229729964241347151442038312944349207021462075732646443668171786595400861104506016915734670330338318506940647492024589840270503991235013262662584958056139456884168786647861529375426433055592755996647363095606998572938173742273727647855395827384610580791486231441743966364638926656177574517783395990477645234920662029069130520169839954328852889679297698894440289360920229577366598674693945253544348773443008431294122902200275761539883366488016392721682618754525310713687607682663191813572550150753228158785842023491267134367643177590897108661282968536031908401081453990449167116430269199694437799218382709284611544863462398344387527482864615346690281888178491568067973361859477877403761036289855293359103434207477896715048195648273965669239199756276403324120343903889368419203819744433704771664793914154135622085625251617910720554457686952006577578494073537754699513783351789231152535131897837873522492614650699226752457363727673079692328753548477123197857803197559269831202493927130425819248457221653733937060671839872590344351995222910813966529070591698808960588220021008665427193485211880949161819748058663187983592657186472030052147851033490886803897240924656263389646409848702846770248392608384734172415681411506756891468425081693839740848739676180437868697906407065835441491240347225077345140389966302714596712069918261923483301431653997283019346596069376
You definitely need some kind of big int library. You can find one quite easily on Google or even (if you plan only specific operations), write one on your own. For instance, the above result comes from my own calculator, which supports big integer evaluations.

How to generate a random number between 0 and a user-defined integer in C/C++? [duplicate]

This question already has answers here:
Generating a random integer from a range
(14 answers)
Closed 9 years ago.
I'm having a problem with my code, in which I try to generate a number between 0 and a dim user-defined variable. The line I'm having problem is:
arrayPos = rand()%dim;
I already called srand(time(NULL)) and the arrayPos is getting some wierd numbers like 9.267e-315 and so on.
Any ideas on how to fix it?
Thank you
The problem really was garbage memory, I restarted the computer and it worked like a charm

What does DIST=AMAX1(0.,DI-DJ) means in Fortran? [duplicate]

This question already has an answer here:
What is meant by . usage after a number in Fortran?
(1 answer)
Closed 3 years ago.
I'm trying to understand a code in fortran language and i don't understand what does
DIST=AMAX1(0.,DI-DJ) means.
I am really confused with the dot(.) next to 0 .
Any help would be appreciated.
Thanks in advance
MAria
AMAX1 is a function for obtaining the maximum value of two or more (single precision) floating point values. The . is there to indicate that the argument is a floating point value and not an integer. 0. is short for 0.0, FORTRAN allows you to omit the decimal zero.
There are lots of FORTRAN references on the Internet. Here is a quick list of intrinsic functions, for example.