[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Hey guys, could you give me any hint as to how to find if a number
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 11
Thread images: 2
File: stressed-student.jpg (169 KB, 283x424) Image search: [Google]
stressed-student.jpg
169 KB, 283x424
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 (19 KB, 337x337) Image search: [Google]
1390364379806.jpg
19 KB, 337x337
>>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 replies: 11
Thread images: 2

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.