MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

Short form for FortranForm

  • Subject: [mg2863] Short form for FortranForm
  • From: "hedonley at grove.iup.edu"@grove.iup.edu
  • Date: 30 Dec 1995 03:45:58 -0600
  • Approved: usenet@wri.com
  • Distribution: local
  • Newsgroups: wri.mathgroup
  • Organization: Indiana University of Pennsylvania
  • Sender: daemon at wri.com

>Subject: Short form for FortranForm
>From: hedonley at grove.iup.edu (H. Edward Donley)
>To: mathgroup at smc.vnet.net
>Organization: Indiana University of PA

Does anyone know how to create FortranForm numbers with just a few digits
of precision, something analogous to the second argument of N[number,
precision]?  My attempt, below, worked for the first example but not for
the second.  And I have a suspicion that there is a much simpler solution.

  In[1]:=
    CompactForm[a_Real, precisiongoal_Integer] :=
      Module[{digits,scalefactor},
        digits = Log[10, Abs[a]];
        scalefactor =
          10^(Sign[digits] Floor[Abs[digits]] - precisiongoal);
        FortranForm[N[ Round[a/scalefactor] scalefactor ]]
      ];
    CompactForm[.0000000005325436656768678,3]
    CompactForm[53254366567686.78,3]

  Out[2]//FortranForm=
    5.33e-10
  Out[3]//FortranForm=
    5.325000000000001e13

Thanks for any help you can give to me.

Ed Donley

-- 
H. Edward Donley
Mathematics Department
Indiana University of Pennsylvania
Indiana, PA  15705
U.S.A.

hedonley at grove.iup.edu
http://www.ma.iup.edu/MathDept/Professors/HDonley.html


  • Prev by Date: Re: Re: FindMinimum and NIntegrate
  • Next by Date: Should I get Matlab or Mathematica or ?
  • Previous by thread: Short form for FortranForm
  • Next by thread: Should I get Matlab or Mathematica or ?