Re: Quick question on math in C
Michael Barton <[email protected]>
| Newsgroups | gmane.games.devel.mud.rom |
|---|---|
| Message-ID | <[email protected]> |
Actually I take that back, abs is in stdlib (for some reason...) so you'll have to #include <stdlib.h>, no extra linking required. On 4/16/05, Michael Barton <[email protected]> wrote: > Or: > variable = -variable; > takes less cpu than multiplying by -1. > > If you use abs, you'll also have to add -lm to the L_FLAGS in your > makefile (to link to the math library). > Or you could just write your own... > int my_abs(int a) > { > return (a < 0) ? -a : a; > } > > On 4/16/05, Ammaross Danan <[email protected]> wrote: > > Number * -1 > > > > Or > > > > #include <math.h> > > Number = abs(Number); > > > > Use the later if you always want it to be positive, the first could > > potentially make it go negative if it was positive to begin with... > > > > Ammaross > > www.rotf.net > > > > -----Original Message----- > > From: [email protected] [mailto:[email protected]] On Behalf Of cyhawk > > Sent: Saturday, April 16, 2005 1:54 PM > > To: [email protected] > > Subject: Quick question on math in C > > > > Err how would i convert a negitive number to a positive number? > > ie -5 to 5 > > or -754 to 754 > > in c? > > > > Google was no help cause i have no idea how to form the question ;) Thanks > > =) > > -- > > ROM mailing list > > [email protected] > > Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom > > > > -- > > ROM mailing list > > [email protected] > > Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom > > > > On 4/16/05, Ammaross Danan <[email protected]> wrote: > > Number * -1 > > > > Or > > > > #include <math.h> > > Number = abs(Number); > > > > Use the later if you always want it to be positive, the first could > > potentially make it go negative if it was positive to begin with... > > > > Ammaross > > www.rotf.net > > > > -----Original Message----- > > From: [email protected] [mailto:[email protected]] On Behalf Of cyhawk > > Sent: Saturday, April 16, 2005 1:54 PM > > To: [email protected] > > Subject: Quick question on math in C > > > > Err how would i convert a negitive number to a positive number? > > ie -5 to 5 > > or -754 to 754 > > in c? > > > > Google was no help cause i have no idea how to form the question ;) Thanks > > =) > > -- > > ROM mailing list > > [email protected] > > Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom > > > > -- > > ROM mailing list > > [email protected] > > Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom > > > -- ROM mailing list [email protected] Unsubscribe here ->>> http://www.rom.org/cgi-bin/mailman/listinfo/rom