To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 1862
1861  |  1863
Subject: 
Floating ponts ??
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Thu, 3 May 2001 19:20:46 GMT
Viewed: 
1457 times
  
Hello everybody

I am writing a program that uses floats, but I have some problems.

If I write
/******/

float p;

p = 0.3;

if(p == 0.4)
   do something;

/******/


The if statement evaluates to true.

Is there anything special I have to do to use floats in legOS? Or am I
doing something wrong. All help will be greatly appreciated.


Niels Sandholt Busch



Message has 3 Replies:
  Re: Floating ponts ??
 
(...) I can't check this out now, but keep e-mailing me until I do. -Kekoa kekoa@graphics.stanford.edu (24 years ago, 4-May-01, to lugnet.robotics.rcx.legos)
  Re: Floating ponts ??
 
(...) Double check the actual program you are test to make sure that you don't have: p = 0.4 /* Only one = */ This is the number one "c" typo and is easy to overlook Lester been there, done that (24 years ago, 4-May-01, to lugnet.robotics.rcx.legos)
  Re: Floating ponts ??
 
Hi there! (...) 0th law of computer science: NEVER use == on floats; it simply doesn't work as expected. In most cases a value cannot be exactly represented as a float variable; so MOST comparisons for equality WILL fail. (this is NOT an issue of (...) (24 years ago, 17-May-01, to lugnet.robotics.rcx.legos)

5 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