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

#IF (TARGET.BITS.PER.WORD = 32)

--{{{  #options and #comments
#OPTION "E V"  -- no compiler libraries, no vector space
#COMMENT "T8 compiler library, V1.1 21/02/89"
#COMMENT "(c) Copyright INMOS Limited 1988"
--}}}

#PRAGMA TRANSLATE LOGB "LOGB%O"

#INCLUDE "realvals.inc"

--{{{  TA, T8, T9000; TA and T8 code merged 20-June-90 SRH
REAL32 FUNCTION LOGB (VAL REAL32 Y)

  REAL32 X :
  VALOF
    --{{{  IEEE single precision VALS for 32-bit processor
    VAL Bias      IS       127 :
    --}}}
    VAL INT Y RETYPES Y:
    INT X.int RETYPES X:
    INT exp, frac :
    SEQ
      exp, frac := SHIFTLEFT (0, (Y<<1), RealShift)
      IF
        (Y << 1) = 0
          X.int := RealInf \/ (MOSTNEG INT)   -- (-inf)
        exp <> RealExp    -- finite
          REAL32 X RETYPES X.int :
          X := REAL32 ROUND (exp - Bias)
        frac = 0          -- inf
          X.int := RealInf
        TRUE              -- NaN
          X.int := Y
    RESULT X
:
--}}}

#ENDIF


#IF (TARGET.BITS.PER.WORD = 16)

--{{{  #options and #comments
#OPTION "V"  -- no vector space
#COMMENT "T2 compiler library, V1.1 21/02/89"
#COMMENT "(c) Copyright INMOS Limited 1988"
--}}}

#PRAGMA TRANSLATE LOGB "LOGB%O"

#INCLUDE "realvals.inc"

--{{{  
REAL32 FUNCTION LOGB (VAL REAL32 Y)

  -- Function version (10 Jun 87)

  REAL32 X :
  VALOF
    --{{{  IEEE single precision VALS FOR 16 bit machine
    VAL SignBit   IS #80000000(INT32) :
    VAL RealInf   IS #7F800000(INT32) :
    VAL Bias      IS       127 :
    --}}}
    VAL [2]INT Y RETYPES Y:
    INT exp,frac :
    SEQ
      exp,  frac := SHIFTLEFT (0,  Y[1]<<1,  RealShift)
      IF
        ((Y[1] << 1) \/ Y[0]) = 0
          INT32 X.int RETYPES X:
          X.int := RealInf \/ SignBit   -- (-inf)
        exp <> RealExp    -- finite
          X := REAL32 ROUND (exp - Bias)
        (frac \/ Y[0]) = 0          -- inf
          INT32 X.int RETYPES X:
          X.int := RealInf
        TRUE                        -- NaN
          VAL REAL32 Y RETYPES Y :
          X := Y
    RESULT X
:
--}}}

#ENDIF
