Computer Science Canada Math.abs |
Author: | xX_MayDay_Xx [ Mon Mar 20, 2006 8:25 am ] |
Post subject: | Math.abs |
ok....i know that Math.abs gives the absolute value of a number..ex(the absolute value of -12...is..12) put i need to know how to do this without using the Math.abs application....i think it has something to do with multipling the number by it's self then dividing by 2? |
Author: | Andy [ Mon Mar 20, 2006 8:26 am ] |
Post subject: | |
how about give us the definition of absolute value, once you understand what it means, this question becomes intuitive |
Author: | xX_MayDay_Xx [ Mon Mar 20, 2006 8:37 am ] | ||
Post subject: | |||
yeah.....i was an idiot......basic rule of math....anything *1 equals its self...that combined with the rules of integers -*+=-....or -*-=+...thats all had to do....i was an idiot...i will no freely except harassment for the uber n()()b...
|
Author: | Andy [ Mon Mar 20, 2006 8:40 am ] |
Post subject: | |
there ya go ![]() |
Author: | xX_MayDay_Xx [ Tue Mar 21, 2006 8:32 am ] |
Post subject: | |
ummm....whats a switch application? |
Author: | Krabjuice [ Tue Mar 21, 2006 2:43 pm ] |
Post subject: | |
Something that uses the switch statement, i'd assume. Switch is a "in the case of" type of control sequence. People generally use if's, but switch has it's uses. |
Author: | Dan [ Tue Mar 21, 2006 3:13 pm ] |
Post subject: | |
I think the most effsent way of doing this whould be to set the singed bit to 0 or what ever means postive on your cpu. Tho this whould probly be a bit complicated for most peoleop and is not real high level progaming but rather low level asm type stuff. I guse this is what Math.abs is for =p. |
Author: | md [ Tue Mar 21, 2006 4:10 pm ] | ||||
Post subject: | |||||
I dunno dan; getting a single bit isn't easy; I think a strait compare might be faster n is $2 $3 is temporary storage compare:
bit-wise
|
Author: | Dan [ Tue Mar 21, 2006 6:40 pm ] |
Post subject: | |
I am prity shure that in asm at least seting one byte to 0 with a mov instruction is faster. |
Author: | md [ Tue Mar 21, 2006 6:47 pm ] |
Post subject: | |
Wha? I'm using words... and I don't set any to zero.. setting the sign bit to 0 instead of 1 would not change the sign of the number at all, it would radically change the number though. 1110 + 0010 = 0000. 0010 is the positive number, 1110 is it's negative. 0110 + 0010 = 1000, clearly not zero ![]() |
Author: | rizzix [ Wed Mar 22, 2006 3:17 pm ] |
Post subject: | |
1101 & 0111 = 0101 ^-- sign bit I believe that's what Dan was aiming for. |
Author: | md [ Wed Mar 22, 2006 4:21 pm ] |
Post subject: | |
yeah, but just checking it is still slow. It's best case two instructions to compare just hte bit, whereas a simple less then is only one. |
Author: | rizzix [ Wed Mar 22, 2006 5:39 pm ] |
Post subject: | |
1101 & 0111 = 0101 ^-- sign bit / resut is a positive number: 0xxx 0110 & 0111 = 0110 ^-- sign bit / result is a positive number 0xxx ![]() |