home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / eiffel / 1313 < prev    next >
Encoding:
Text File  |  1992-11-17  |  3.1 KB  |  93 lines

  1. Newsgroups: comp.lang.eiffel
  2. Path: sparky!uunet!ukma!darwin.sura.net!uvaarpa!murdoch!cds001.cebaf.gov!quarrie
  3. From: quarrie@cds001.cebaf.gov (David Quarrie)
  4. Subject: Re: if then else  strange things..
  5. Message-ID: <1992Nov17.193605.405@murdoch.acc.Virginia.EDU>
  6. Sender: usenet@murdoch.acc.Virginia.EDU
  7. Reply-To: quarrie@cds001.cebaf.gov (David Quarrie)
  8. Organization: CEBAF (Continuous Electron Beam Accelerator Facility)
  9. References:  <1992Nov17.164713.6958@purelogic.cs.uwlax.edu>
  10. Date: Tue, 17 Nov 1992 19:36:05 GMT
  11. Lines: 80
  12.  
  13. --
  14. In article <1992Nov17.164713.6958@purelogic.cs.uwlax.edu>,
  15. butte_ms@pascal.uwlax.edu (Mike S. Butterbrodt S92) writes:
  16. |>Newsgroups: comp.lang.eiffel
  17. |>Path:
  18. |
  19. murdoch!uvaarpa!darwin.sura.net!zaphod.mps.ohio-state.edu!saimiri.primat
  20. te.wisc.edu!zazen!purelogic!usenet
  21. |>From: butte_ms@pascal.uwlax.edu (Mike S. Butterbrodt S92)
  22. |>Subject: if then else  strange things..
  23. |>Message-ID: <1992Nov17.164713.6958@purelogic.cs.uwlax.edu>
  24. |>Sender: usenet@purelogic.cs.uwlax.edu (News Poster)
  25. |>Nntp-Posting-Host: pascal.wing.uwlax.edu
  26. |>Organization: University of Wisconsin - La Crosse Computer Science
  27. |>Department
  28. |>Date: Tue, 17 Nov 1992 16:47:13 GMT
  29. |>Lines: 36
  30. |>
  31. |> Gotta neat problem......
  32. |> 
  33. |> For a class we are creating a logic gate simulator.  In one of the
  34. |>gates, we  
  35. |>toggle the color with
  36. |> a mouse down event.  (From Black to Light_gray).  
  37. |> 
  38. |> We are using Postscript commands on a NeXT enviroment, but that
  39. |>should be  
  40. |>irrelevant for this problem.   
  41. |> 
  42. |> 
  43. |> My first attempt was ::::
  44. |>       -- When the gates are initially created      status_color := 
  45. |>Black;
  46. |>       
  47. |>    the mouse_down event method contains this (among other non-related
  48. |>things)
  49. |>    
  50. |>               if  status_color = Light_gray then
  51. |>               status_color := Black;
  52. |>          else
  53. |>                status_color := Light_gray;
  54. |>            end;     
  55. |>            display;
  56. |> This changed the color to Light_gray, but would not change it back on
  57. |>|>successive mouse downs.
  58. |> However, this worked.....
  59. |> 
  60. |>                if  status_color = Black then
  61. |>               status_color := Light_gray;
  62. |>          else
  63. |>                status_color := Black;
  64. |>            end;     
  65. |>            display;
  66. |>
  67. |>It works now, so I am happy.  But this is very curious.  Any
  68. |>answers???
  69. |>
  70. |>                                         Mike Butterbrodt,  UW_La
  71. |>Crosse Comp.  
  72. |>Sci.
  73. |>
  74.  
  75. I think the problem is floating point comparisons. Black is defined as 0.0 (I
  76. think, I'm not in front of my NeXT right now so will have to check
  77. later) whereas
  78. Light_gray is defined as 0.67 (or thereabouts). Checking against 0.0 is
  79. exact
  80. but checking against 0.67 is not exact (because the floating point 
  81. representations are not exact). I hate to think how many times that
  82. caught me 
  83. during my FORTRAN coding days!
  84.  
  85. No doubt someone will correct me if I'm talking through a hole in my head.
  86.  
  87. -------------------------------------------------------------------------------
  88.     David Quarrie                    CEBAF MS 12H
  89.                             12000 Jefferson Ave
  90. Internet: quarrie@cebaf.gov                Newport News VA 23606
  91. DECnet  : cebaf::quarrie                Tel: (804) 249-7562
  92. BITNET  : quarrie@cebaf                    Fax: (804) 249-7363
  93.