--
--	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

#IF NOT DEFINED(OCCBUILD.KROC)

#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 tangent.
--
-- @param X Angle in radians
-- @return Tangent of X
REAL64 FUNCTION DTAN (VAL REAL64 X)

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

  REAL64 RWork :
  VALOF
    IF
      DNOTFINITE (X)
        --{{{  Inf or NaN
        IF
          DISNAN (X)
            RWork := X    -- transmit NaN
          TRUE
            RWork := Dundefined.NaN
        --}}}
      TRUE
        --{{{  variables
        REAL64 XWork :
        INT32 N :
        BOOL ok :
        --}}}
        SEQ
          ok, N, XWork := DARGUMENT.REDUCE (X, DPiBy2, DPiBy2.err)
          IF
            ok  -- argument reduction was accurate
              REAL64 XNum, XDen :
              SEQ
                --{{{  approximation in primary range
                -- XWork is in the range [-Pi/4, Pi/4]
                VAL P3 IS -1.7861707342254426711E-5(REAL64) :
                VAL P2 IS  3.4248878235890589960E-3(REAL64) :
                VAL P1 IS -1.3338350006421960681E-1(REAL64) :
                VAL Q4 IS  4.9819433993786512270E-7(REAL64) :
                VAL Q3 IS -3.1181531907010027307E-4(REAL64) :
                VAL Q2 IS  2.5663832289440112864E-2(REAL64) :
                VAL Q1 IS -4.6671683339755294240E-1(REAL64) :
                VAL Q0 IS  1.0(REAL64) :
                VAL G IS XWork * XWork :
                SEQ
                  XNum := (((((((P3*G)+P2)*G)+P1)*G)*XWork)+XWork)
                  XDen := ((((((((Q4*G)+Q3)*G)+Q2)*G)+Q1)*G)+Q0)
                --}}}
                --{{{  construct result
                IF
                  ((N /\ one) = 0(INT32)) -- N even
                    RWork := REAL64OP (XNum, Div, XDen)
                  XNum = DZero
                    RWork := Dunstable.NaN
                  TRUE
                    RWork := REAL64OP ((-XDen), Div, XNum)
                --}}}
            TRUE -- argument reduction not accurate
              RWork := Dinexact.NaN
    RESULT RWork
:

#ENDIF
