--
--	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 SCALEB "SCALEB%O"

#INCLUDE "realvals.inc"

--{{{  T8 and TA are the same; merged 20-June-90 SRH
REAL32 FUNCTION SCALEB (VAL REAL32 Y, VAL INT n)

  -- Halt version: optimised 27-jul-87 PWT
  -- Halt and undefined: Beta-2 (27feb87)

  VAL Bias      IS 127 :
  REAL32 X :
  VALOF
    INT m :
    VAL INT maxexp IS  126:
    VAL INT minexp IS -126:
    VAL REAL32 Two.to.the.maxexp RETYPES #7E800000(INT32) :
    VAL REAL32 Two.to.the.minexp RETYPES #00800000(INT32) :
    SEQ
      X := Y
      m := n
      WHILE m <> 0
        IF
          m > maxexp
            SEQ
              X := X * Two.to.the.maxexp
              m := m - maxexp
          m < minexp
            SEQ
              X := X * Two.to.the.minexp
              m := m - minexp
          TRUE
            INT Z.int :
            SEQ
              INT temp:
              temp,  Z.int := SHIFTRIGHT ((m + Bias),  0,  RealShift + 1)
              REAL32 Z RETYPES Z.int :
              X := X * Z
              m := 0
    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 SCALEB "SCALEB%O"

#INCLUDE "realvals.inc"

--{{{  T2
REAL32 FUNCTION SCALEB (VAL REAL32 Y, VAL INT n)

  -- Beta-2 (27feb87)
  -- 27-jul-87

  VAL Bias      IS 127 :
  REAL32 X :
  VALOF
    INT m :
    INT temp:
    VAL INT maxexp IS  126:
    VAL INT minexp IS -126:
    VAL REAL32 Two.to.the.maxexp RETYPES #7E800000(INT32) :
    VAL REAL32 Two.to.the.minexp RETYPES #00800000(INT32) :
    SEQ
      X := Y
      m := n
      WHILE m <> 0
        IF
          m > maxexp
            SEQ
              X := X * Two.to.the.maxexp
              m := m - maxexp
          m < minexp
            SEQ
              X := X * Two.to.the.minexp
              m := m - minexp
          TRUE
            [2]INT Z.int :
            PLACE Z.int IN WORKSPACE :
            SEQ
              Z.int[0] := 0
              temp,  Z.int[1] := SHIFTRIGHT ((m + Bias),  0,  RealShift + 1)
              REAL32 Z RETYPES Z.int :
              X := X * Z
              m := 0
    RESULT X
:
--}}}

#ENDIF
