home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / bsd / 4379 < prev    next >
Encoding:
Text File  |  1992-08-18  |  5.1 KB  |  324 lines

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!usc!rpi!newsserver.pixel.kodak.com!laidbak!tellab5!vpnet!serveme!tallboy!news
  2. From: kunst@prl.philips.nl (Pieter Kunst)
  3. Newsgroups: comp.unix.bsd
  4. Subject: pow bug fix
  5. Message-ID: <9208170849.AA17863@hpas1.prl.philips.nl>
  6. Date: Mon, 17 Aug 92 10:49:53 +0200
  7. Sender: news@tallboy.chi.il.us
  8. Reply-To: kunst@prl.philips.nl
  9. Lines: 313
  10.  
  11. I fixed the pow(-2,3) bug in DJGPP version 1.07 (and below).
  12. As the diff -c3 file is almost as long as the fixed file, 
  13. I send both; use whichever is of most convenience...
  14.  
  15. Pieter Kunst (kunst@prl.philips.nl)
  16.  
  17. ------------ demo program (test.c) below this line --------------------
  18.  
  19. #include <stdio.h>
  20. extern double pow(double,double);
  21.  
  22. main()
  23. {
  24.   printf ("pow(-2,2) = %g\n", pow(-2,2));              /* 4 */
  25.   printf ("pow(-2,3) = %g\n", pow(-2,3));              /* -8 */
  26.   printf ("pow(2,3.1) = %g\n", pow(2,3.1));            /* 8.574188 */
  27.   printf ("pow(-2,3.1) = %g\n", pow(-2,3.1));          /* DOMAIN error */
  28. }
  29.  
  30. ---------------- demo makefile below this line -----------------------
  31.  
  32. #
  33. PROG = test
  34. OBJ  = test.o exp.o
  35.  
  36. .c.o:
  37.     gcc -c $<
  38.  
  39. .s.o:
  40.     gcc -c $<
  41.  
  42. $(PROG): $(OBJ)
  43.     gcc $(OBJ) -o $(PROG)
  44.  
  45. ---------------- fixed exp.s below this line -------------------------
  46.  
  47. /* This is file EXP.S */
  48. /*
  49. ** Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  50. **
  51. ** Modified O.ROBERT 24, Avenue de Verdun 92170 VANVES, FRANCE
  52. **
  53. ** E-mail: roberto@germinal.ibp.fr
  54. **
  55. ** This file is distributed under the terms listed in the document
  56. ** "copying.dj", available from DJ Delorie at the address above.
  57. ** A copy of "copying.dj" should accompany this file; if not, a copy
  58. ** should be available from where this file was obtained.  This file
  59. ** may not be distributed without a verbatim copy of "copying.dj".
  60. **
  61. ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  62. ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  63. **
  64. ** or    03-Apr-1991    corrected bug about argument zero to pow
  65. **            fyl2x didn't like it
  66. **
  67. ** 17-08-92: modified to fix pow(-2,3) bug by kunst@prl.philips.nl
  68. **           pow(x,y)  x^y.  A domain error occurs if x=0 and y<=0,
  69. **                         or if x<0 and y is not an integer.
  70. **
  71. */
  72.  
  73. /* History:15,24 */
  74.     .data
  75. yint: 
  76.     .word   0,0
  77. LCW1:
  78.     .word    0
  79. LCW2:
  80.     .word    0
  81.  
  82.     .text
  83. LC0:
  84.     .double    0d1.0e+00
  85.  
  86. frac:
  87.     fstcww    LCW1
  88.     fstcww    LCW2
  89.     fwait
  90.     andw    $0xf3ff,LCW2
  91.     orw    $0x0400,LCW2
  92.     fldcww    LCW2
  93.     fldl    %st(0)
  94.     frndint
  95.     fldcww    LCW1
  96.     fxch    %st(1)
  97.     fsub    %st(1),%st
  98.     ret
  99.  
  100.     .globl    _pow2
  101. _pow2:
  102.     fldl    4(%esp)
  103. Lpow2:
  104.     call    frac
  105.     f2xm1
  106.     faddl    LC0
  107.     fscale
  108.     fstp    %st(1)
  109.     ret
  110.  
  111.     .globl    _exp
  112. _exp:
  113.     fldl    4(%esp)
  114.     fldl2e
  115.     fmulp
  116.     jmp    Lpow2
  117.  
  118.     .globl    _pow10
  119. _pow10:
  120.     fldl    4(%esp)
  121.     fldl2t
  122.     fmulp
  123.     jmp    Lpow2
  124.  
  125.     .globl    _pow
  126. _pow:
  127.     fldl    12(%esp)
  128.     fldl    4(%esp)
  129.     ftst    
  130.     fnstsww    %ax
  131.     sahf
  132.     jbe    xltez
  133.     fyl2x
  134.     jmp    Lpow2
  135. xltez:
  136.     jb    xltz
  137.     fstp    %st(0)
  138.     ftst
  139.     fnstsww    %ax
  140.     sahf
  141.     ja    ygtz
  142.     jb    error
  143.     fstp    %st(0) 
  144.     fld1l
  145.     fchs
  146. error:
  147.     fsqrt
  148.     ret
  149. ygtz:
  150.     fstp    %st(0)
  151.     fldzl
  152.     ret
  153. xltz:
  154.     fabs
  155.     fxch    %st(1)
  156.     call    frac
  157.     ftst
  158.     fnstsww    %ax
  159.     fstp    %st(0)
  160.     sahf
  161.     je    yisint
  162.     fstp    %st(0)
  163.     fchs
  164.     jmp    error
  165. yisint:
  166.     fistl    yint
  167.     fxch    %st(1)
  168.     fyl2x
  169.     call    Lpow2
  170.     andl    $1,yint
  171.     jz    yeven
  172.     fchs
  173. yeven:
  174.     ret
  175.  
  176. ---------------- diff -c3 starts below this line ---------------------
  177.  
  178. *** exp.org    Mon Aug 17 10:26:53 1992
  179. --- exp.s    Mon Aug 17 10:33:45 1992
  180. ***************
  181. *** 17,26 ****
  182. --- 17,33 ----
  183.   **
  184.   ** or    03-Apr-1991    corrected bug about argument zero to pow
  185.   **            fyl2x didn't like it
  186. + **
  187. + ** 17-08-92: modified to fix pow(-2,3) bug by kunst@prl.philips.nl
  188. + **           pow(x,y)  x^y.  A domain error occurs if x=0 and y<=0,
  189. + **                         or if x<0 and y is not an integer.
  190. + **
  191.   */
  192.   
  193.   /* History:15,24 */
  194.       .data
  195. + yint: 
  196. +     .word   0,0
  197.   LCW1:
  198.       .word    0
  199.   LCW2:
  200. ***************
  201. *** 27,40 ****
  202.       .word    0
  203.   
  204.       .text
  205.   LC0:
  206.       .double    0d1.0e+00
  207.   
  208. !     .globl    _pow2
  209. ! _pow2:
  210. !     fldl    4(%esp)
  211. ! Lpow2:
  212.       fstcww    LCW1
  213.       fstcww    LCW2
  214.       fwait
  215. --- 34,43 ----
  216.       .word    0
  217.   
  218.       .text
  219.   LC0:
  220.       .double    0d1.0e+00
  221.   
  222. ! frac:
  223.       fstcww    LCW1
  224.       fstcww    LCW2
  225.       fwait
  226. ***************
  227. *** 46,51 ****
  228. --- 49,61 ----
  229.       fldcww    LCW1
  230.       fxch    %st(1)
  231.       fsub    %st(1),%st
  232. +     ret
  233. +     .globl    _pow2
  234. + _pow2:
  235. +     fldl    4(%esp)
  236. + Lpow2:
  237. +     call    frac
  238.       f2xm1
  239.       faddl    LC0
  240.       fscale
  241. ***************
  242. *** 68,92 ****
  243.   
  244.       .globl    _pow
  245.   _pow:
  246.       fldl    4(%esp)
  247.       ftst
  248. !     fnstsww %ax
  249.       sahf
  250. !     je    zero1
  251. !     fldl    12(%esp)
  252.       ftst
  253. !     fnstsww %ax
  254.       sahf
  255. !     je    zero2
  256. !     fxch    %st(1)
  257.       fyl2x
  258. !     jmp    Lpow2
  259. ! zero1:
  260. !     fstpl    4(%esp)
  261. !     fldzl
  262.       ret
  263. ! zero2:
  264. !     fstpl    4(%esp)
  265. !     fstpl    4(%esp)
  266. !     fld1l
  267. !     ret
  268. --- 78,129 ----
  269.   
  270.       .globl    _pow
  271.   _pow:
  272. +     fldl    12(%esp)
  273.       fldl    4(%esp)
  274. +     ftst    
  275. +     fnstsww    %ax
  276. +     sahf
  277. +     jbe    xltez
  278. +     fyl2x
  279. +     jmp    Lpow2
  280. + xltez:
  281. +     jb    xltz
  282. +     fstp    %st(0)
  283.       ftst
  284. !     fnstsww    %ax
  285.       sahf
  286. !     ja    ygtz
  287. !     jb    error
  288. !     fstp    %st(0) 
  289. !     fld1l
  290. !     fchs
  291. ! error:
  292. !     fsqrt
  293. !     ret
  294. ! ygtz:
  295. !     fstp    %st(0)
  296. !     fldzl
  297. !     ret
  298. ! xltz:
  299. !     fabs
  300. !     fxch    %st(1)
  301. !     call    frac
  302.       ftst
  303. !     fnstsww    %ax
  304. !     fstp    %st(0)
  305.       sahf
  306. !     je    yisint
  307. !     fstp    %st(0)
  308. !     fchs
  309. !     jmp    error
  310. ! yisint:
  311. !     fistl    yint
  312. !     fxch    %st(1)
  313.       fyl2x
  314. !     call    Lpow2
  315. !     andl    $1,yint
  316. !     jz    yeven
  317. !     fchs
  318. ! yeven:
  319.       ret
  320.  
  321.