abs() function operator

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2005
Posts: 14
Reputation: dallin is an unknown quantity at this point 
Solved Threads: 0
dallin dallin is offline Offline
Newbie Poster

abs() function operator

 
0
  #1
Jan 29th, 2005
I'm using the abs() function in a probability calculation using float and int variables however I'm getting error messages. What I'm trying to do is get a decimal answer using abs() but it appears to only accept integer variables? How do I get the abs() to give me a a 3 decimal place answer.
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 2
Reputation: picogeek is an unknown quantity at this point 
Solved Threads: 0
picogeek picogeek is offline Offline
Newbie Poster

Re: abs() function operator

 
0
  #2
Jan 29th, 2005
Try the fabs() function for floating point numbers.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: abs() function operator

 
0
  #3
Jan 31st, 2005
abs function is for doubles...fabs is for floats
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,364
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 242
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: abs() function operator

 
0
  #4
Jan 31st, 2005
Originally Posted by Acidburn
abs function is for doubles...fabs is for floats
No. Care to try again?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,047
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 935
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: abs() function operator

 
0
  #5
Jan 31st, 2005
Roll your own, it's just too simple ...
[php]
if (number < 0) number = -number;
[/php]
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: abs() function operator

 
0
  #6
Jan 31st, 2005
Originally Posted by Dave Sinkula
No. Care to try again?
its not? thats what my linux help manual said
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,364
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 242
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: abs() function operator

 
0
  #7
Jan 31st, 2005
Originally Posted by Acidburn
its not? thats what my linux help manual said
Really?

http://www.rt.com/man/abs.3.html:
int abs(int j);

http://www.rt.com/man/fabs.3.html:
double fabs(double x);
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: abs() function operator

 
0
  #8
Jan 31st, 2005
don't supose you could explain that a little more, I got the feeling that fabs and abs do different things pther than double and floats?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,364
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 242
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: abs() function operator

 
0
  #9
Jan 31st, 2005
Given the prototypes, I thought it was quite obvious. (You didn't follow the links and read the descriptions either, did you?)
  • abs is for int (not double)
  • fabs is for floating point (double or float)
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: abs() function operator

 
0
  #10
Jan 31st, 2005
Originally Posted by Dave Sinkula
Given the prototypes, I thought it was quite obvious. (You didn't follow the links and read the descriptions either, did you?)
  • abs is for int (not double)
  • fabs is for floating point (double or float)
i followed the links ..............never mind
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC