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

#IF NOT DEFINED(TARGET.HAS.FPU)

--{{{  #options and #comments
#OPTION "V"  -- no vector space
#COMMENT "TA compiler library, V1.2 09/07/90"
#COMMENT "(c) Copyright INMOS Limited 1988"
--}}}

#PRAGMA TRANSLATE ABS "ABS%O"
#PRAGMA TRANSLATE FPINT "FPINT%O"

#INCLUDE "realvals.inc"

#IF (TARGET.BITS.PER.WORD = 32)
--{{{  ABS
--{{{  
REAL32 FUNCTION ABS (VAL REAL32 Y)

  -- Stop on error version: Beta-2 (27feb87)
  -- Halt and undefined:    16-sep-87

  REAL32 X :
  VAL RealInf IS #7F800000 :
  VALOF
    INT X RETYPES X:
    VAL INT Y RETYPES Y:
    SEQ
      X := Y /\ (~(MOSTNEG INT))
      IF
        (X /\ RealInf) = RealInf
          CAUSEERROR() -- to be compatible with T8
        TRUE
          SKIP
    RESULT X
:
--}}}
--}}}
#ENDIF -- TARGET.BITS.PER.WORD = 32
#IF (TARGET.BITS.PER.WORD = 16)
--{{{  ABS
--{{{  
REAL32 FUNCTION ABS (VAL REAL32 Y)

  -- Function version (10 Jun 87)
  -- Stop version error behaviour modified 16-sep-87

  REAL32 X :
  VALOF
    VAL RealInf IS #7F80 :
    [2]INT X RETYPES X:
    VAL [2]INT Y RETYPES Y:
    SEQ
      X[0] := Y[0]
      X[1] := Y[1] /\ (~(MOSTNEG INT))
      IF
        (X[1] /\ RealInf) = RealInf -- Inf or NaN
          CAUSEERROR()
        TRUE
          SKIP
    RESULT X
:
--}}}
--}}}
#ENDIF -- TARGET.BITS.PER.WORD = 16

--{{{  FPINT
--{{{  T2 and TA code is the same; amalgamated 9-Jul-90 SRH
REAL32 FUNCTION FPINT (VAL REAL32 X)

  -- rounding mode corrected 20 Aug 87 PWT
  -- V1.1, 21-Feb-89
  -- Corrected action for small negative X; V1.2, 9-July-90 SRH

  REAL32 Res :
  VALOF
    VAL REAL32 largest.non.integer IS REAL32 ROUND ( 1( INT32 ) << BitsInFrac ) :
    IF
      ABS(X) > largest.non.integer  -- nothing after decimal point anyway
        Res := X
      TRUE
        REAL32 temp :
        SEQ
          -- IEEE 754-1985 Sec 6.3 says that the sign must be preserved;
          -- do in the following way because INT32 ROUND has no concept
          -- of -0
          temp := REAL32 ROUND (INT32 ROUND X)
          VAL INT32 temp.int32 RETYPES temp :
          VAL INT32 X.int32 RETYPES X :
          INT32 Res.int32 RETYPES Res :
          Res.int32 := temp.int32 \/ ( X.int32 /\ ( MOSTNEG INT32 ) )
    RESULT Res
:
--}}}
--}}}

#ENDIF
