Results 1 to 4 of 4

Thread: floating point

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    This code is not allowed with floating points, it doesn't matter if it's 8 bytes or 4, there are always accuracy errors:
    Code:
    if car_pos = point_a then
    You can do it for example like this:
    Code:
    if abs(car_pos - point_a)<0.001 then
    But this is also extremely rarely used way...

    Normally you should organize code so that you can check:
    Code:
    if car_pos >= point_a then
    edit: I'll show what i mean by your code:
    Code:
      while True do begin
        car_pos := car_pos + car_speed;
        writeln('car position :',car_pos:2:2);
        if car_pos >= point_b then begin
           writeln('we are in point b');
           break;
        end else if car_pos >= point_a then
           writeln('we are beyond point a, but before point_b');
     end;
    Last edited by User137; 23-09-2011 at 02:27 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •