[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Voyeur Cams | Click for more| Home]

Hey guys, could you give me any hint as to how to find if a number

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.
Voyeur Cams

Thread replies: 11
Thread images: 2

File: stressed-student.jpg (169KB, 283x424px) Image search: [iqdb] [SauceNao] [Google]
stressed-student.jpg
169KB, 283x424px
Hey guys, could you give me any hint as to how to find if a number is even or odd in assembly language, mainly MIPS. I have to write a code that calculates Pi using floating point registers and my code would work 100% if I just knew how to make the conditions right for even or odd values. I was thinking of doing division and subtracting the number divided by the result but idk.
>>
File: 1390364379806.jpg (19KB, 337x337px) Image search: [iqdb] [SauceNao] [Google]
1390364379806.jpg
19KB, 337x337px
>>51567310
look at the lsb you trog
>>
>>51567361
They're floating points, if it was a regular integer that'd be easy but I'm too tired/retarded to figure out how to set this up using the lsb
>>
>>51567361
could i shift the result 31 times to the left and then see if its zero or not?
>>
>>51567361
He's talking floating point numbers.

>>51567310
I think the idea of dividing by two and subtracting that quotient from the original number twice is a reasonable solution. Just be sure that when you do a compare that you don't compare to zero.

That is, using pseudo code:

double dbl1;
double dbl2;
...

dbl2 = dbl1 / 2.0;

// Fudge factor is some very small number since dbl1 - dbl2 - dbl2 might not be exactly zero in FP arithmetic.
if ((dbl1 - dbl2 - dbl2) < dblFudgeFactor)
{
// Divisible by two
}

else
{
// Not divisible by two
}
>>
>>51567430
whats the reason for you subtracting dbl2 twice from dbl1?
>>
>>51567505
dbl2 is half of dbl1. E.g.

dbl1 = 8.0;
dbl2 = 8.0 / 2.0; // dbl2 = 4.0

// dbl1 - dbl2 - dbl2 should be close to zero in FP representation.
>>
>>51567399
>>51567430
Whoops. I like the divide by 2 method suggested.
>>
>>51567430
I'm rusty on my floating point number representations, but you might need to take the absolute value of the result before comparing with dblFudgeFactor
>>
>>51567690
You're correct. It's been a very long time since I've had to do anything with floating point numbers especially in assembly.
>>
>>51567725
>>51567690
Thanks for your help guys. I'm trying my best to get this bullshit to work. Assembly is my first programming language ever and I want to die.
Thread posts: 11
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]
Please support this website by donating Bitcoins to 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
If a post contains copyrighted or illegal content, please click on that post's [Report] button and fill out a post removal request
All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site. This means that 4Archive shows an archive of their content. If you need information for a Poster - contact them.