Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2 of the GNU General Public License as 00007 published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU General Public License along 00021 with this program; if not, write the Free Software Foundation, Inc., 59 00022 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00023 00024 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00025 Mountain View, CA 94043, or: 00026 00027 http://www.sgi.com 00028 00029 For further information regarding this notice, see: 00030 00031 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00032 00033 */ 00034 00035 00036 #include <inttypes.h> 00037 #include "quad.h" 00038 00039 /* intrinsic QINT */ 00040 00041 /* by value version */ 00042 00043 /* truncates a long double, i.e. computes the integral part of 00044 a long double 00045 */ 00046 00047 extern double __trunc(double); 00048 00049 extern double fabs(double); 00050 #pragma intrinsic (fabs) 00051 00052 typedef union 00053 { 00054 struct 00055 { 00056 uint32_t hi; 00057 uint32_t lo; 00058 } word; 00059 00060 double d; 00061 } du; 00062 00063 static const du twop52 = 00064 {0x43300000, 0x00000000}; 00065 00066 long double 00067 __qint(double uhi,double ulo ) 00068 { 00069 ldquad result; 00070 00071 #include "msg.h" 00072 00073 if ( uhi != uhi ) 00074 { 00075 result.q.hi = uhi; 00076 result.q.lo = ulo; 00077 00078 return ( result.ld ); 00079 } 00080 00081 if ( uhi >= 0.0 ) 00082 { 00083 if ( uhi < twop52.d ) 00084 { 00085 /* binary point occurs in uhi; truncate uhi to an integer 00086 */ 00087 00088 result.q.hi = __trunc(uhi); 00089 00090 result.q.lo = 0.0; 00091 00092 if ( result.q.hi < uhi ) 00093 return ( result.ld ); 00094 00095 /* must adjust result by one if ulo < 0.0 */ 00096 00097 if ( ulo < 0.0 ) 00098 { 00099 result.q.hi -= 1.0; 00100 00101 return ( result.ld ); 00102 } 00103 00104 return ( result.ld ); 00105 } 00106 else if ( fabs(ulo) < twop52.d ) 00107 { 00108 /* binary point occurs in ulo; truncate ulo to an integer 00109 */ 00110 00111 result.q.hi = uhi; 00112 00113 result.q.lo = __trunc(ulo); 00114 00115 if ( result.q.lo > ulo ) 00116 { 00117 result.q.lo -= 1.0; 00118 } 00119 00120 return ( result.ld ); 00121 } 00122 00123 /* arg is an integer */ 00124 00125 result.q.hi = uhi; 00126 result.q.lo = ulo; 00127 00128 return ( result.ld ); 00129 } 00130 else 00131 { 00132 if ( fabs(uhi) < twop52.d ) 00133 { 00134 /* binary point occurs in uhi; truncate uhi to an integer 00135 */ 00136 00137 result.q.hi = __trunc(uhi); 00138 00139 result.q.lo = 0.0; 00140 00141 if ( result.q.hi > uhi ) 00142 return ( result.ld ); 00143 00144 /* must adjust result by one if ulo > 0.0 */ 00145 00146 if ( ulo > 0.0 ) 00147 { 00148 result.q.hi += 1.0; 00149 00150 return ( result.ld ); 00151 } 00152 00153 return ( result.ld ); 00154 } 00155 else if ( fabs(ulo) < twop52.d ) 00156 { 00157 /* binary point occurs in ulo; truncate ulo to an integer 00158 */ 00159 00160 result.q.hi = uhi; 00161 00162 result.q.lo = __trunc(ulo); 00163 00164 if ( result.q.lo < ulo ) 00165 { 00166 result.q.lo += 1.0; 00167 } 00168 00169 return ( result.ld ); 00170 } 00171 00172 /* arg is an integer */ 00173 00174 result.q.hi = uhi; 00175 result.q.lo = ulo; 00176 00177 return ( result.ld ); 00178 } 00179 00180 } 00181