🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #9

Re: Absolute value??

#9
From: Michael D'Errico
Date: Wed, 28 Oct 1992 04:32
27 lines
1176 bytes
In article <1cfe73INN1o5@clover.csv.warwick.ac.uk> maupb@csv.warwick.ac.uk (Mr J L Saunders) writes:

]In article <94562@netnews.upenn.edu> mmuhamad@pixmap.seas.upenn.edu (Mohd Zaki Muhamad) writes:
]>Hi,
]>
]>   Do any of you out there know any function that can turn all data
]>(negative or positive) to be positive...i mean in absolute value
]>so that I can compare them and find  which one is the largest?  For your info,
]>I am addressing this question to C language programmer.  Is the function
]>defined in the math.h?   Thanks.

]The functions you want are:

]int abs(i)
]int i;

]#include <math.h>

]double fabs(x)
]double x;

Or, you could use a macro which does not care about the specific types of the data.
A simple one is:

#define ABS(x) (((x)>=0) ? (x):(-(x)))

Mike
Technical Details
Message-ID: <6285@ucsbcsl.ucsb.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!ferkel.ucsb.edu!ucsbcsl!ucsbuxa!6500msd
References: <94562@netnews.upenn.edu> <1cfe73INN1o5@clover.csv.warwick.ac.uk>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ferkel.ucsb.edu!ucsbcsl!ucsbuxa!6500msd
From: 6500msd@ucsbuxa.ucsb.edu (Michael D'Errico)
Newsgroups: comp.unix.programmer
Subject: Re: Absolute value??
Message-ID: <6285@ucsbcsl.ucsb.edu>
Date: 28 Oct 92 04:32:38 GMT
References: <94562@netnews.upenn.edu> <1cfe73INN1o5@clover.csv.warwick.ac.uk>
Sender: news@ucsbcsl.ucsb.edu
Lines: 28