To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.handyboardOpen lugnet.robotics.handyboard in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / Handy Board / 7071
7070  |  7072
Subject: 
Re: mixing variable types in IC
Newsgroups: 
lugnet.robotics.handyboard
Date: 
Sun, 14 Nov 1999 20:24:24 GMT
Original-From: 
Richard Drushel <DRUSHEL@APKnospam.NET>
Viewed: 
786 times
  
[Ben Davis] spake unto the ether:

int x, y;
float c;

float divide ( int x, int y)
{
        c = (float) (x/y);
        return c;
}

Hmm, I think you want

c = ((float)(x))/((float)(y));

Otherwise, the division will be done first as integers, giving an integer
quotient, which you're then turning into a float.

*Rich*
--
Richard F. Drushel, Ph.D.            | "Aplysia californica" is your taxonomic
Department of Biology, Slug Division | nomenclature.  /  A slug, by any other
Case Western Reserve University      | name, is still a slug by nature.
Cleveland, Ohio  44106-7080  U.S.A.  |     -- apologies to Data, "Ode to Spot"



Message is in Reply To:
  mixing variable types in IC
 
Hi John- You can convert quantities from one data type to another (it's called "casting", I believe). The following computes the quantity x/y, then converts it to a float: ---...--- int x, y; float c; float divide ( int x, int y) { c = (float) (...) (25 years ago, 14-Nov-99, to lugnet.robotics.handyboard)

2 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR