Float.st
changeset 19091 12b1f7ebf405
parent 18857 7165f748d240
child 19103 71257a47eba2
child 19326 aa152894e736
equal deleted inserted replaced
19090:c044866c92eb 19091:12b1f7ebf405
     1 "{ Encoding: utf8 }"
       
     2 
       
     3 "
     1 "
     4  COPYRIGHT (c) 1988 by Claus Gittinger
     2  COPYRIGHT (c) 1988 by Claus Gittinger
     5 	      All Rights Reserved
     3 	      All Rights Reserved
     6 
     4 
     7  This software is furnished under a license and may be used
     5  This software is furnished under a license and may be used
  1788 %{
  1786 %{
  1789     double rslt;
  1787     double rslt;
  1790     OBJ newFloat;
  1788     OBJ newFloat;
  1791 
  1789 
  1792     if (__isFloatLike(n)) {
  1790     if (__isFloatLike(n)) {
  1793 	__threadErrno = 0;
  1791         __threadErrno = 0;
  1794 	rslt = pow(__floatVal(self), __floatVal(n));
  1792         rslt = pow(__floatVal(self), __floatVal(n));
  1795 	if (! isnan(rslt))  /* Currently all our systems support isnan() */
  1793         if (! isnan(rslt))  /* Currently all our systems support isnan() */
  1796 	{
  1794         {
  1797 	    if (__threadErrno == 0) {
  1795             if (__threadErrno == 0) {
  1798 		__qMKFLOAT(newFloat, rslt);
  1796                 __qMKFLOAT(newFloat, rslt);
  1799 		RETURN ( newFloat );
  1797                 RETURN ( newFloat );
  1800 	    }
  1798             }
  1801 	}
  1799         }
  1802     }
  1800     }
  1803 %}.
  1801 %}.
       
  1802     "/ the c-library pow functin, has a bug:
       
  1803     "/ it does not deal correctly with negative numbers. 
       
  1804     "/ I.e. it raises an error on -8^(1/3) instead of returning a negative -2
       
  1805     "/ work around with a kludge:
       
  1806     self < 0 ifTrue:[
       
  1807         ^ (self negated raisedTo:n) negated
       
  1808     ].
       
  1809 
  1804     "
  1810     "
  1805      an invalid argument (not convertable to float ?)
  1811      an invalid argument (not convertable to float ?)
  1806     "
  1812     "
  1807     ^ self class
  1813     ^ self class
  1808 	raise:#domainErrorSignal
  1814         raise:#domainErrorSignal
  1809 	receiver:self
  1815         receiver:self
  1810 	selector:#raisedTo:
  1816         selector:#raisedTo:
  1811 	arguments:(Array with:aNumber)
  1817         arguments:(Array with:aNumber)
  1812 	errorString:'bad receiver/arg in raisedTo:'
  1818         errorString:'bad receiver/arg in raisedTo:'
  1813 
  1819 
  1814     "Modified: / 16.11.2001 / 14:16:51 / cg"
  1820     "Modified: / 16.11.2001 / 14:16:51 / cg"
  1815 !
  1821 !
  1816 
  1822 
  1817 sqrt
  1823 sqrt