CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

-1= abs(0-1) Isnt this wrong??

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
carterson2



Joined: 27 Aug 2006
Posts: 5
Location: Memphis

View user's profile Send private message Visit poster's website

-1= abs(0-1) Isnt this wrong??
PostPosted: Tue Oct 31, 2006 9:47 am     Reply with quote

Hi,
Does ABSOLUTE value work? Mine doesnt, see below... Thanks
------------------------------------------------------------------------

#include <16f877a.h>
#define compiler __PCM__
#include "stdlib.h"

main()
{
int a;
int b=13,c=16;

a= abs(b-c);

//it comes out a= 253 ugh....

}
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Oct 31, 2006 9:55 am     Reply with quote

Ints default to unsigned, so b-c=253, abs(253)=253, so a=253 just as it ought to.

Perhapse you should declare your variables as "signed int".
_________________
The search for better is endless. Instead simply find very good and get the job done.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group