home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / fortran / 5200 < prev    next >
Encoding:
Text File  |  1993-01-28  |  1.9 KB  |  42 lines

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!charon.amdahl.com!amdahl!rtech!pacbell.com!ames!agate!dog.ee.lbl.gov!hellgate.utah.edu!lanl!cochiti.lanl.gov!jlg
  3. From: jlg@cochiti.lanl.gov (J. Giles)
  4. Subject: Re: IAND,IOR... - Thank you
  5. Message-ID: <1993Jan26.190831.8026@newshost.lanl.gov>
  6. Sender: news@newshost.lanl.gov
  7. Organization: Los Alamos National Laboratory
  8. References:  <1k1dcdINNpm3@rs2.hrz.th-darmstadt.de>
  9. Date: Tue, 26 Jan 1993 19:08:31 GMT
  10. Lines: 30
  11.  
  12. In article <1k1dcdINNpm3@rs2.hrz.th-darmstadt.de>, kroeker@oc1.oc.chemie.th-darmstadt.de (Martin Kroeker) writes:
  13. |> Many thanks to all who responded to my query about coding non-standard
  14. |> bit manipulation functions in fortran, especially to Eric Haug, who provided
  15. |> the simple (ouch !) solution in C:
  16. |> long btest (long *a, long *b)
  17. |>            return(*a>>*b);
  18.  
  19. This is clearly an incorrect solution.  Suppose the first argument is
  20. eight and the second is one, this version of btest returns four - which
  21. is *not* the value of the bit addressed by the second argument in either
  22. big- or little-endian bit numbering.  In little-endian, the following
  23. operation would be correct:
  24.  
  25.   long btest (long *a, long *b)
  26.              return(*a>>*b & 1);
  27.  
  28. |> After my plea for help I had finally found a clumsy solution in fortran, but
  29. |> this one naturally beats it easily.
  30.  
  31. I've never run across a Fortran implementation which did not have 
  32. these as operations as either intrinsic functions or operators which 
  33. are inlined and which use the hardware instructions (if the hardware 
  34. has them) to perform these operations.  A glance at the document for 
  35. your particular Fortran implementation would probably have revealed a 
  36. non-clumsy Fortran solution.  Certainly it's less clumsy to use a
  37. implementation defined extension to Fortran than to rely on C (the
  38. interface to which is also implementation defined and not portable).
  39.  
  40. -- 
  41. J. Giles
  42.