[J3] C TS 18661

Steven G. Kargl kargl at troutmask.apl.washington.edu
Thu Jan 31 02:05:40 EST 2019


On Thu, Jan 31, 2019 at 05:19:23AM +0000, Bill Long via J3 wrote:
> 
> > On Jan 30, 2019, at 7:08 PM, Van Snyder via J3 <j3 at mailman.j3-fortran.org> wrote:
> > 
> > On Wed, 2019-01-30 at 15:44 -0500, Steve Lionel via J3 wrote:
> >> Please don't think that I am objecting - I have no position on these new 
> >> suggestions at this time. I was just pointing out that they would not be 
> >> "standardizing existing practice".
> > 
> > I pointed out in my original post in this thread that expm1 and logp1
> > (and sinpi instead of sind, etc) are in the C TS 18661.  I further
> > pointed out that Fortran appearing to lag behind C for scientific and
> > engineering applications is not good advertising.
> > 
> 
> Is C really used for new scientific and engineering applications these days?

Of course, some people use C for scientific programming.  Would you like
a copy of my C code that solves the Khokhlov-Zabolotskaya-Kuznetsov (kzk)
equation?

> I had thought that the main non-Fortran languages for those domains were now
> C++ (with a negative growth rate) and Python (with a definitely positive growth rate). 

Most languages leverage what is available in the operating system's math library.
So, C++ likely use libm just like C does.

> Also, if these routines are part of the required math library for C,
> can’t Fortran programmers just call them directly using bind(c) interfaces?
>   !6.9 already has 199 subclauses.  It seems that adding yet more intrinsics
> should have a fairly high use case threshold for justification.

Can you call a libm function with a bind(c) interface in an
initialization expression?  No.  Inhibits optimiziations.

Can a compiler *easily* perform constant folding for a libm function
with a bind(c) interface?  The answer with gfortran is 'no', and I 
suspect it is 'no' for most, if not all, other processors.  Again,
inhibits optimization.

Can you call a libm function with a bind(c) interface with
an array argument?  No. The elemental attribute seems to
conflict with bind(c).

! This seems to be fairly readable.
program foo
  real, parameter :: x(3) = sinpi([0.0, 0.5, 1.0])
  print *, x
end program 

program foo
  use iso_c_binding
  interface
     ! elemental conflicts with bind(c)
     elemental function sinpi(x) bind(c, name='sinpi')
        import c_float
        real(c_float) sinpi
        real(c_float), intent(in), value :: x
     end function
  end interface
  ! Impossible to define named constants
  real, parameter :: x(3) = sinpi([0.0, 0.5, 1.0])
  print *, x
end program

-- 
Steve


More information about the J3 mailing list