home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / lib / libc / tahoe / gen / ldexp.s < prev    next >
Encoding:
Text File  |  1991-04-12  |  3.9 KB  |  110 lines

  1. /*
  2.  * Copyright (c) 1988 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * This code is derived from software contributed to Berkeley by
  6.  * Computer Consoles Inc.
  7.  *
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in the
  15.  *    documentation and/or other materials provided with the distribution.
  16.  * 3. All advertising materials mentioning features or use of this software
  17.  *    must display the following acknowledgement:
  18.  *    This product includes software developed by the University of
  19.  *    California, Berkeley and its contributors.
  20.  * 4. Neither the name of the University nor the names of its contributors
  21.  *    may be used to endorse or promote products derived from this software
  22.  *    without specific prior written permission.
  23.  *
  24.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34.  * SUCH DAMAGE.
  35.  */
  36.  
  37. #if defined(LIBC_SCCS) && !defined(lint)
  38.     .asciz "@(#)ldexp.s    5.4 (Berkeley) 1/30/91"
  39. #endif /* LIBC_SCCS and not lint */
  40.  
  41. /*
  42.  * double ldexp (value, exp)
  43.  *    double value;
  44.  *    int exp;
  45.  *
  46.  * Ldexp returns value*2**exp, if that result is in range.
  47.  * If underflow occurs, it returns zero.  If overflow occurs,
  48.  * it returns a value of appropriate sign and largest
  49.  * possible magnitude.  In case of either overflow or underflow,
  50.  * the external int "errno" is set to ERANGE.  Note that errno is
  51.  * not modified if no error occurs, so if you intend to test it
  52.  * after you use ldexp, you had better set it to something
  53.  * other than ERANGE first (zero is a reasonable value to use).
  54.  *
  55.  * Constants
  56.  */
  57.  
  58. /*
  59.  * we can't include errno.h anymore, ANSI says that it defines errno.
  60.  *
  61.  * #include <errno.h>
  62.  */
  63. #define    ERANGE    34
  64. #include <tahoe/math/fp.h>
  65.  
  66. #include "DEFS.h"
  67.  
  68. ENTRY(ldexp, 0)
  69.     movl    4(fp),r0    /* Fetch "value" */
  70.     movl    8(fp),r1    
  71.  
  72.     andl3    $EXPMASK,r0,r2    /* r2 := shifted biased exponent */
  73.     jeql    ld1        /* If it's zero, we're done */
  74.     shar    $EXPSHIFT,r2,r2    /* shift to get value of exponent  */
  75.  
  76.     addl2    12(fp),r2    /* r2 := new biased exponent */
  77.     jleq    under        /* if it's <= 0, we have an underflow */
  78.     cmpl    r2,$256        /* Otherwise check if it's too big */
  79.     jgeq    over        /* jump if overflow */
  80. /*
  81. *    Construct the result and return
  82. */
  83.     andl2    $0!EXPMASK,r0    /* clear old exponent */
  84.     shal     $EXPSHIFT,r2,r2    /* Put the exponent back in the result */
  85.     orl2    r2,r0
  86. ld1:    ret
  87. /*
  88. *    Underflow
  89. */
  90. under:    clrl    r0        /* Result is zero */
  91.     clrl    r1
  92.     jbr    err        /* Join general error code */
  93. /*
  94. *    Overflow
  95. */
  96. over:    movl    huge0,r0    /* Largest possible floating magnitude */
  97.     movl    huge1,r1
  98.     jbc    $31,4(fp),err    /* Jump if argument was positive */
  99.     orl2    $SIGNBIT,r0    /* If arg < 0, make result negative */
  100.  
  101. err:    movl    $ERANGE,_errno    /* Indicate range error */
  102.     ret
  103.  
  104.     .data
  105.     .globl    _errno        /* error flag */
  106. huge0:    .word    0x7fff        /* The largest number that can */
  107.     .word    0xffff        /*   be represented in a long floating */
  108. huge1:    .word    0xffff        /*   number.  */
  109.     .word    0xffff        
  110.