|
-
Nov 24th, 2003, 10:49 PM
#1
Thread Starter
Addicted Member
negative to positive
Hi,
This is a really easy question I'm sure but I can't figure it out in a simple way.
Let's say I have A + B = C
and A is 100 and B is -200 so C = -100
How can I get C as a positive number?
I need this for a rectangle drawing function I'm writing where the mouse down and mouse up coordinates can be positive or negative.
What I'm really looking for is the difference between A and B as a positive number.
Any help?
Thanks
T
-
Nov 25th, 2003, 02:10 AM
#2
Dazed Member
x - y is the same as x + (-y) so in your case wouldnt you get a negative value either way? if this is supposed to be coded why don't you just use C's absolute value?
Last edited by Dilenger4; Nov 25th, 2003 at 02:16 AM.
-
Nov 25th, 2003, 07:26 AM
#3
I'm guessing that as it is rectangles all lines are horizontal or vertical, in which case Something Else's code is a little over the top (but required if lines are at an angle) . In VB you can do this:
C = Abs(A + B)
-
Nov 25th, 2003, 12:43 PM
#4
Frenzied Member
If not in VB, then do this:
if C < 0 then
C= 0-C
end if
Have I helped you? Please Rate my posts. 
-
Nov 26th, 2003, 04:30 AM
#5
There's an absolute function in nearly every language.
Mathematical notation is
|a|
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 28th, 2003, 03:42 PM
#6
Frenzied Member
You could also multiply by -1
-
Nov 28th, 2003, 04:02 PM
#7
C = 0 - C
or
C = -C
is probably faster than
C = C * -1
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 28th, 2003, 05:44 PM
#8
Frenzied Member
And if its in C, you could do
C *=-1;
-
Nov 29th, 2003, 07:42 AM
#9
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 29th, 2003, 04:36 PM
#10
Hyperactive Member
C *=-1;
is the same as C = C * (-1)
but C = 0-C is definitely faster(a littttttttttttttttttttttle)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|