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 / 1879
1878  |  1880
Subject: 
Re: Floating ponts ??
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Thu, 17 May 2001 07:21:37 GMT
Viewed: 
1500 times
  
Hi there!

float p;

p = 0.3;

if(p == 0.4)
   do something;

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 legOS, it holds true for any language,
compiler, runtime, processor, ...)
(you may compare to 0 (zero); 0 is exactly represented as float)


bis die Tage...
  Mathias



Message has 1 Reply:
  Re: Floating ponts ??
 
(...) Exceptions to the 0th law: You are manipulating and comparing floating-point values you know are integers with a magnitude less than a million or two. You are manipulating and comparing values you know are integer multiples of some power of (...) (24 years ago, 17-May-01, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  Floating ponts ??
 
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 (...) (24 years ago, 3-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

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

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