Welcome to Dream.In.Code
Become an Expert!

Join 137,420 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,981 people online right now. Registration is fast and FREE... Join Now!




how to get the sign of a variable

 
Reply to this topicStart new topic

how to get the sign of a variable

bhadranv
22 Jan, 2008 - 04:55 AM
Post #1

New D.I.C Head
*

Joined: 22 Jan, 2008
Posts: 1

I like to know the logic of getting the sign of a variable. I don't want any
code. One way of doing it is by dividing the vaiable by its absolute value.
But what will happen if the variable is zero? So this method doesn't work.
What is the alternative?
User is offlineProfile CardPM
+Quote Post

girasquid
RE: How To Get The Sign Of A Variable
22 Jan, 2008 - 06:39 AM
Post #2

Barbarbar
Group Icon

Joined: 3 Oct, 2006
Posts: 1,267



Thanked: 14 times
Dream Kudos: 650
My Contributions
One method I've used is comparing the variable to its absolute value - if they match, it's positive. If they don't, it's negative.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/5/08 04:19AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month