--
--	Inmos Libraries
--	Copyright (C) 1988, 1989, 1990, 1991, 1993  Inmos Limited
--
--	This library is free software; you can redistribute it and/or
--	modify it under the terms of the GNU Lesser General Public
--	License as published by the Free Software Foundation; either
--	version 2 of the License, or (at your option) any later version.
--
--	This library is distributed in the hope that it will be useful,
--	but WITHOUT ANY WARRANTY; without even the implied warranty of
--	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
--	Lesser General Public License for more details.
--
--	You should have received a copy of the GNU Lesser General Public
--	License along with this library; if not, write to the Free Software
--	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
--

--** @module maths

#OPTION "V"  -- no vector space
#COMMENT "Floating point maths library, V1.1 27/03/90"
#COMMENT "(c) Copyright INMOS Limited 1988"
#INCLUDE "mathhdr.inc"

--* Double-precision arcsine.
--
-- @param X Input value in the range [@text [-1.0, 1.0]]
-- @return Arcsine of X in radians
REAL64 FUNCTION DASIN (VAL REAL64 X)

  --{{{  history
  -- V1.0 1-Jul-88
  -- Added OPTION "V"; V1.1 27-Mar-90 SRH
  --}}}

  REAL64 Result :
  VALOF
    IF
      DNOTFINITE (X)
        --{{{  Infs and NaNs
        IF
          DISNAN(X)
            Result := X
          TRUE
            Result := Dundefined.NaN
        --}}}
      --{{{  definitions
      VAL P IS [-6.9674573447350646411E-1(REAL64),
                 1.0152522233806463645E+1(REAL64),
                -3.9688862997504877339E+1(REAL64),
                 5.7208227877891731407E+1(REAL64),
                -2.7368494524164255994E+1(REAL64)] :
      VAL Q IS [-2.3823859153670238830E+1(REAL64),
                 1.5095270841030604719E+2(REAL64),
                -3.8186303361750149284E+2(REAL64),
                 4.1714430248260412556E+2(REAL64),
                -1.6421096714498560795E+2(REAL64)] :
      VAL XWork IS DABS (X) :
      --}}}
      IF
        XWork > DOne
          Result := Dundefined.NaN
        XWork = DOne
          --{{{  result depends on sign
          IF
            X < DZero
              Result := - DPiBy2
            TRUE
              Result := DPiBy2
          --}}}
        XWork > DHalf
          --{{{  reduce argument & compute result
          REAL64 Y, G :
          SEQ
            G := DDIVBY2 (DOne - XWork)
            Y := - DMULBY2 (DSQRT (G))
            Y := (Y+(Y*
                  ((((((((((P[0]*G)+P[1])*G)+P[2])*G)+P[3])*G)+P[4])*G)/
                  (((((((((G+Q[0])*G)+Q[1])*G)+Q[2])*G)+Q[3])*G)+Q[4]))))
            IF
              X < DZero
                Result := - (Y + DPiBy2)
              TRUE
                Result := Y + DPiBy2
          --}}}
        TRUE
          --{{{  remaining case
          VAL G IS X * X :
          Result :=  X+(X*
                     ((((((((((P[0]*G)+P[1])*G)+P[2])*G)+P[3])*G)+P[4])*G)/
                     (((((((((G+Q[0])*G)+Q[1])*G)+Q[2])*G)+Q[3])*G)+Q[4])))
          --}}}
    RESULT Result
:
