home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / MAGAZINE / DDJ9309.ZIP / FPALIB.ZIP / FFMLIB.C < prev    next >
C/C++ Source or Header  |  1993-05-12  |  20KB  |  677 lines

  1. /* Extended IEEE Compatible Floating Point Arithmetic Library
  2. **
  3. ** Version 1.0
  4. ** Copyright (C) 1990, by Fred Motteler
  5. ** All Rights Reserved
  6. **
  7. ** Floating point support routines.  The routines below are used only
  8. ** by the floating point routines.
  9. */
  10. #include <stdio.h>
  11. #ifndef MWC
  12. #include <stdlib.h>
  13. #endif
  14. #include "imlib.h"
  15. #include "ffmlib.h"
  16. #include "fmlib.h"
  17.  
  18. /*
  19. ** Function:    unsigned char ffchkzero(unsigned char *resultPB, int totalenN)
  20. **
  21. ** Check if the floating point value is zero.  If so, then return zero.
  22. ** Otherwise return a non-zero value.  Note that this routine works only
  23. ** if the floating point number has a length that is a byte multiple.
  24. ** (8, 16, 24, ... bits in length) or if the floating point number is
  25. ** padded with zeros out to the next byte boundary.
  26. */
  27. unsigned char
  28. #ifdef PROTOTYPES
  29. ffchkzero(unsigned char *resultPB, int totalenN)
  30. #else
  31. ffchkzero(resultPB, totalenN)
  32. unsigned char *resultPB;
  33. int totalenN;
  34. #endif
  35. {
  36.     int i;
  37.     unsigned char bitorB;
  38.  
  39.     bitorB = 0;
  40.     for (i = 0; i < totalenN; i++)
  41.     bitorB |= (*(resultPB + i));
  42.     return(bitorB);
  43. }
  44.  
  45. /*
  46. ** Function:    unsigned char ffexpchk(unsigned char *prodexpPB, int expbyteN,
  47. **                       unsigned char *expbiasPB, int expbitN,
  48. **                       unsigned char expccB );
  49. **
  50. ** This function checks for exponent overflow (or underflow).
  51. **
  52. ** Note that the integer addition/subtraction routines only catch overflows
  53. ** if the exponent size is a multiple of a byte, i.e.: 8, 16, 24, ...
  54. ** This routine catchs overflows when the exponent size is not a multiple
  55. ** of a byte.
  56. */
  57. unsigned char
  58. #ifdef PROTOTYPES
  59. ffexpchk(unsigned char *prodexpPB, int expbyteN, unsigned char *expbiasPB,
  60.      int expbitN, unsigned char expccB)
  61. #else
  62. ffexpchk(prodexpPB, expbyteN, expbiasPB, expbitN, expccB)
  63. unsigned char *prodexpPB;
  64. int expbyteN;
  65. unsigned char *expbiasPB;
  66. int expbitN;
  67. unsigned char expccB;
  68. #endif
  69. {
  70.     unsigned char *tempexpPB;
  71.     unsigned char tempccB;
  72.     int i;
  73.  
  74.     /* Check if exponent size is a multiple of a byte.  Return if so, since
  75.      * the integer add/subtract routine will have properly caught the
  76.      * overflow condition. */
  77.     if ((expbitN % 8) == 0)
  78.     return (expccB);
  79.  
  80.     /* The exponent size is such that there are "extra" bits in the array
  81.      * used to keep the exponent.  These extra bits prevent the integer
  82.      * add/subtract routine from catching the overflow condition.  As
  83.      * a result, the overflow must be explicitly checked for.  Initially
  84.      * allocate space for temporary results and initialize with the
  85.      * exponent value to test. */
  86.     tempexpPB = (unsigned char *) FMALLOC(expbyteN, "FFEXPCHK");
  87.     for (i = 0; i < expbyteN; i++)
  88.     *(tempexpPB + i) = *(prodexpPB + i);
  89.  
  90.     /* Use the SIGN bit to determine if the resulting exponent was positive
  91.      * or negative.  The SIGN bit should be valid in all cases since the
  92.      * sign bit is automatically extended by the integer add/subtract
  93.      * routines.  Also note that the proper sign bits were initially
  94.      * generated when the exponent bias was subtracted off. */
  95.     if (expccB & SIGN)
  96.     {
  97.     /* Result is negative, check if it is less than the negative of
  98.      * the exponent bias.  This is done by adding the exponent bias
  99.      * to the value and checking if the result is still negative. */
  100.     tempccB = iaddm(tempexpPB, expbiasPB, expbyteN);
  101.     if ((tempccB & SIGN) != 0)
  102.         expccB |= OVERFLOW;
  103.     }
  104.     else
  105.     {
  106.     /* Result is positive, check if it is greater than the exponent
  107.      * bias.  This is done by subtracting the exponent bias and checking
  108.      * if the result is still positive. */
  109.     tempccB = isubm(tempexpPB, expbiasPB, expbyteN);
  110.     if ((tempccB & SIGN) == 0)
  111.         expccB |= OVERFLOW;
  112.     }
  113.     FFREE(tempexpPB);
  114.     return (expccB);
  115. }
  116.  
  117. /*
  118. ** Function:    unsigned char ffexpover(unsigned char *resultPB, int totalenN,
  119. **                    unsigned char expccB,
  120. **                    unsigned char *expbiasPB, int expbyteN,
  121. **                    unsigned char *exponePB,
  122. **                    unsigned char condcodeB, int fracbitN,
  123. **                    int expbitN);
  124. **
  125. ** This is a rather specialized function to deal with the overflow or
  126. ** underflow condition.  Depending on the state of the "expccB" condition
  127. ** codes, either an overflow or underflow is assumed to have occurred.  If
  128. ** an overflow has occurred, then infinity is written out to the result
  129. ** pointed to by resultPB.  If an underflow has occurred, then zero is written
  130. ** out to the result.  In either case, a modified version of the condition
  131. ** codes (initially in condcodeB) is returned.
  132. **
  133. ** Note that the value of the exponent bias is modified to be be "all one's"
  134. ** in the exponent field.
  135. */
  136. unsigned char
  137. #ifdef PROTOTYPES
  138. ffexpover(unsigned char *resultPB, int totalenN, unsigned char expccB,
  139.       unsigned char *expbiasPB, int expbyteN, unsigned char *exponePB,
  140.       unsigned char condcodeB, int fracbitN, int expbitN)
  141. #else
  142. ffexpover(resultPB, totalenN, expccB, expbiasPB, expbyteN, exponePB, condcodeB,
  143.       fracbitN, expbitN)
  144. unsigned char *resultPB;
  145. int totalenN;
  146. unsigned char expccB;
  147. unsigned char *expbiasPB;
  148. int expbyteN;
  149. unsigned char *exponePB;
  150. unsigned char condcodeB;
  151. int fracbitN;
  152. int expbitN;
  153. #endif
  154. {
  155.     int i;
  156.  
  157.     /* We have either a floating point overflow or underflow. 
  158.      * Initially zero the result. */
  159.     for (i = 0; i < totalenN; i++)
  160.     *(resultPB + i) = 0;
  161.     /* Check for overflow or underflow.  Note that when an over/underflow
  162.      * occurs, the sign of the result is opposite the expected result if no
  163.      * over/underflow had occurred. */
  164.     if ((expccB & SIGN) == 0)
  165.     {
  166.     /* We have floating point underflow, leave the result zero,
  167.      * and set the zero condition code. */
  168.     condcodeB |= FFZERO;
  169.     return(condcodeB);
  170.     }
  171.  
  172.     /* We have floating point overflow, write out infinity.  This
  173.      * requires setting the exponent to its maximum value.  The
  174.      * maximum value is equal to twice the exponent bias plus 1. */
  175.     ushftlm(expbiasPB, expbyteN);
  176.     iaddm(expbiasPB, exponePB, expbyteN);
  177.  
  178.     /* Stuff the maximum exponent value into the result field. */
  179.     ffbitins(expbiasPB, expbyteN, fracbitN, expbitN, resultPB, totalenN);
  180.  
  181.     condcodeB |= FFINF;
  182.     return(condcodeB);
  183. }
  184.  
  185. /*
  186. ** Function:    unsigned char ffsetsign(unsigned char signoneB,
  187. **                    unsigned char signtwoB,
  188. **                    unsigned char *resultPB, int totalenN,
  189. **                    int signposN, unsigned char condcodeB)
  190. **
  191. ** This is a rather specialized function that sets the sign bit (if
  192. ** appropriate) in the result value pointed to by resultPB.
  193. */
  194. unsigned char
  195. #ifdef PROTOTYPES
  196. ffsetsign(unsigned char signoneB, unsigned char signtwoB,
  197.       unsigned char *resultPB, int totalenN, int signposN,
  198.       unsigned char condcodeB)
  199. #else
  200. ffsetsign(signoneB, signtwoB, resultPB, totalenN, signposN, condcodeB)
  201. unsigned char signoneB, signtwoB;
  202. unsigned char *resultPB;
  203. int totalenN;
  204. int signposN;
  205. unsigned char condcodeB;
  206. #endif
  207. {
  208.     if (signoneB == signtwoB)
  209.     {
  210.      /* pos. result if original signs the same */
  211.     ffbitclr(resultPB, totalenN, signposN);
  212.     }
  213.     else
  214.     {
  215.     /* neg. result if original signs different */
  216.     ffbitset(resultPB, totalenN, signposN);
  217.     condcodeB |= FFNEG;
  218.     }
  219.     return(condcodeB);
  220. }
  221.  
  222. /*
  223. ** Function:    void ffbitext(unsigned char *srcPB, int srclenN, int sbitN,
  224. **                  int bitlenN, unsigned char *destPB, int destlenN)
  225. **
  226. ** Extract a bit field from the source location to the destination.
  227. **
  228. **    srcPB points to the first byte of
  229. **    the source.
  230. **        |
  231. **    |ssssssss|ssssssss|ssssssss|ssssssss|
  232. **           |               |
  233. **           |---------------|
  234. **                |         sbitN gives the starting bit of
  235. **                |         the source field (starting with
  236. **                |         ls bit of the last byte of the
  237. **                |         source. (sbitN = 0 as shown.)
  238. **                |
  239. **                bitlenN gives the length of the source
  240. **                field in bits. (bitlenN = 23 as shown.)
  241. **
  242. **    destPB points to the last byte of the destination.
  243. **
  244. **    NOTE:
  245. **    1) destlenN must be greater than or equal to (bitlenN >> 3) + 1.
  246. **       No explicit checking of lengths is done.
  247. **    2) destPB and srcPB point to the first byte of the source and
  248. **       destination bit field arrays, but are immediately convertered to
  249. **       pointers that point to the LAST (least significant) byte of
  250. **       source and destination bit field arrays!!!  This is totally unlike
  251. **       normal usage, but is required since bit fields are always
  252. **       referenced relative to the least significant bit.
  253. */
  254. void
  255. #ifdef PROTOTYPES
  256. ffbitext(unsigned char *srcPB, int srclenN, int sbitN, int bitlenN,
  257.      unsigned char *destPB, int destlenN)
  258. #else
  259. ffbitext(srcPB, srclenN, sbitN, bitlenN, destPB, destlenN)
  260. unsigned char *srcPB;
  261. int srclenN;
  262. int sbitN;
  263. int bitlenN;
  264. unsigned char *destPB;
  265. int destlenN;
  266. #endif
  267. {
  268.     int stbyteN, stbitN, tranlenN, i;
  269.     int endbyteN, endbitN;
  270.     int clearbitN;
  271.     unsigned char *tempbufPB;
  272.     unsigned char *tempptrPB;
  273.  
  274.     /* Convert the source pointer from most significant
  275.      * byte pointer format to least signficant byte pointer format. */
  276.     srcPB += (srclenN - 1);
  277.  
  278.     /* Determine where the start bit is located at. */
  279.     stbyteN = sbitN >> 3;
  280.     stbitN = sbitN & 0x7;
  281.  
  282.     /* Determine where the end bit is located at.  Note that if bitlenN
  283.      * is 1, then the start and end bit are the same bit. */
  284.     endbyteN = (sbitN + bitlenN - 1) >> 3;
  285.     endbitN = (sbitN + bitlenN - 1) & 0x7;
  286.  
  287.     /* Point at byte containing bit. */
  288.     srcPB -= stbyteN;
  289.  
  290.     /* Determine the number of bytes to copy to destination.  Note that
  291.      * things can get tricky if the start bit is not the least significant
  292.      * bit of the start byte, and the most significant bit is also not
  293.      * on a byte boundary. */
  294.     tranlenN = endbyteN - stbyteN + 1;
  295.  
  296.     /* Allocate a temporary buffer for working on the value.  Initialize
  297.      * working point one byte past where it would normally go.  The
  298.      * reason for going one byte past is that the exract routine can
  299.      * go one byte too far in some circumstances. */
  300.     tempbufPB = (unsigned char *) FCALLOC((destlenN + 1), 1, "FFBITEXT");
  301.     tempptrPB = tempbufPB + destlenN;
  302.  
  303.     /* Copy source bytes to temporary buffer destination. */
  304.     for (i = 0; i < tranlenN; i++)
  305.     {
  306.         *tempptrPB-- = *srcPB--;
  307.     }
  308.     tempptrPB++;        /* Point to msb of temporary buffer */
  309.  
  310.     /* Figure out how much of the ms bits of the ms byte of the
  311.      * destination must be cleared, and then clear it */
  312.     clearbitN = (sbitN + bitlenN) % 8;
  313.     *tempptrPB &= ffclearmaskAB[clearbitN];
  314.     /* Shift the destination bits into the proper place */
  315.     for (i = 0; i < stbitN; i++)
  316.     ushftrm(tempptrPB, tranlenN);
  317.  
  318.     /* Copy the result from the temporary buffer back into the destination
  319.      * buffer. */
  320.     tempptrPB = tempbufPB + 1;
  321.     for (i = 0; i < destlenN; i++)
  322.     *(destPB + i) = *tempptrPB++;
  323.     
  324.     FFREE(tempbufPB);
  325.     return;
  326. }
  327.  
  328. /*
  329. ** Function:    void ffbitins(unsigned char *srcPB, int srclenN, int dbitN,
  330. **                  int bitlenN, unsigned char *destPB,
  331. **                  int destlenN)
  332. **
  333. ** Insert a bit field to the destination from the source location.
  334. **
  335. **    destPB points to the first byte of
  336. **    the destination.
  337. **    |
  338. **    |dddddddd|dddddddd|dddddddd|dddddddd|
  339. **           |               |
  340. **           |---------------|
  341. **                |         dbitN gives the starting bit of
  342. **                |         the destination field (starting
  343. **                |         with ls bit of the last byte of
  344. **                |         the destination. (dbitN = 0 as
  345. **                |         shown.)
  346. **                |
  347. **                bitlenN gives the length of the destination
  348. **                field in bits. (bitlenN = 23 as shown.)
  349. **
  350. **    srcPB points to the first byte of the destination.
  351. **
  352. **    NOTE:
  353. **    1) destlenN must be greater than or equal to (bitlenN >> 3) + 1.
  354. **       No explicit checking of lengths is done.
  355. **    2) destPB and srcPB point to the first (most significant) byte
  356. **       of the source and destination bit field arrays, but are
  357. **       immediately converted to point to the LAST (least significant)
  358. **       byte...  This is totally unlike
  359. **       normal usage, but is required since bit fields are always
  360. **       referenced relative to the least significant bit.  (And by doing
  361. **       this, these routines don't care how long the actual source and
  362. **       destination fields are...)
  363. */
  364. void
  365. #ifdef PROTOTYPES
  366. ffbitins(unsigned char *srcPB, int srclenN, int dbitN, int bitlenN,
  367.      unsigned char *destPB, int destlenN)
  368. #else
  369. ffbitins(srcPB, srclenN, dbitN, bitlenN, destPB, destlenN)
  370. unsigned char *srcPB;
  371. int srclenN;
  372. int dbitN;
  373. int bitlenN;
  374. unsigned char *destPB;
  375. int destlenN;
  376. #endif
  377. {
  378.     int stbyteN, stbitN, bitoN, i;
  379.  
  380.     /* Convert the source and destination pointers from most significant
  381.      * byte pointer format to least signficant byte pointer format. */
  382.     srcPB += (srclenN - 1);
  383.     destPB += (destlenN - 1);
  384.  
  385.     /* Determine where the start bit is located at. */
  386.     stbyteN = dbitN >> 3;
  387.     stbitN = dbitN & 0x7;
  388.  
  389.     /* Point at byte containing first destination bit. */
  390.     destPB -= stbyteN;
  391.  
  392.     /* Loop thru the source bits, stuffing one at a time into the destination.
  393.      * This is done one at a time so as to not disturb the other bits.
  394.      * If there is a better way to do this, let me know!!! */
  395.     i = 0;            /* Start with low bit of source */
  396.     bitoN = 0;
  397.     while (i < bitlenN)
  398.     {
  399.     if ((*srcPB & ffsetmaskAB[bitoN]) == 0)
  400.         *destPB &= ffclrmaskAB[stbitN];
  401.     else
  402.         *destPB |= ffsetmaskAB[stbitN];
  403.  
  404.     i++;
  405.     /* Check if at end of current source and destination bytes */
  406.     if (bitoN++ == 7)
  407.     {
  408.         bitoN = 0;
  409.         srcPB--;
  410.     }
  411.     if (stbitN++ == 7)
  412.     {
  413.         stbitN = 0;
  414.         destPB--;
  415.     }
  416.     }
  417.     return;
  418. }
  419.  
  420.  
  421. /*
  422. ** Function:    void ffbitset(unsigned char *srcPB, int srclenN, int nbitN)
  423. **
  424. ** Set the "nbitN" of the value pointed to by srcPB.
  425. **
  426. ** As with the ffbitext() function above, srcPB points to the FIRST (most
  427. ** significant) byte of the value to set the nth bit of.
  428. */
  429. void
  430. #ifdef PROTOTYPES
  431. ffbitset(unsigned char *srcPB, int srclenN, int nbitN)
  432. #else
  433. ffbitset(srcPB, srclenN, nbitN)
  434. unsigned char *srcPB;
  435. int srclenN;
  436. int nbitN;
  437. #endif
  438. {
  439.     int stbyteN, stbitN;
  440.  
  441.     /* Convert the source pointer from most significant
  442.      * byte pointer format to least signficant byte pointer format. */
  443.     srcPB += (srclenN - 1);
  444.  
  445.     /* Determine where the bit to set is located at. */
  446.     stbyteN = nbitN >> 3;
  447.     stbitN = nbitN & 0x7;
  448.  
  449.     /* Point at byte containing bit. */
  450.     srcPB -= stbyteN;
  451.  
  452.     /* Set the appropriate bit */
  453.     *srcPB |= ffsetmaskAB[stbitN];
  454.  
  455.     return;
  456. }
  457.  
  458. /*
  459. ** Function:    void ffbitclr(unsigned char *srcPB, int srclenN, int nbitN)
  460. **
  461. ** Clear the "nbitN" of the value pointed to by srcPB.
  462. **
  463. ** As with the ffbitext() function above, srcPB points to the FIRST (most
  464. ** significant) byte of the value to clear the nth bit of.
  465. */
  466. void
  467. #ifdef PROTOTYPES
  468. ffbitclr(unsigned char *srcPB, int srclenN, int nbitN)
  469. #else
  470. ffbitclr(srcPB, srclenN, nbitN)
  471. unsigned char *srcPB;
  472. int srclenN;
  473. int nbitN;
  474. #endif
  475. {
  476.     int stbyteN, stbitN;
  477.  
  478.     /* Convert the source pointer from most significant
  479.      * byte pointer format to least signficant byte pointer format. */
  480.     srcPB += (srclenN - 1);
  481.  
  482.     /* Determine where the bit to set is located at. */
  483.     stbyteN = nbitN >> 3;
  484.     stbitN = nbitN & 0x7;
  485.  
  486.     /* Point at byte containing bit. */
  487.     srcPB -= stbyteN;
  488.  
  489.     /* Set the appropriate bit */
  490.     *srcPB &= ffclrmaskAB[stbitN];
  491.  
  492.     return;
  493. }
  494.  
  495. /*
  496. ** Function:    unsigned char fftstbit(unsigned char *srcPB, int srclenN,
  497. **                       int nbitN )
  498. **
  499. ** Test the "nbitN" of the value pointed to by srcPB.
  500. **
  501. ** As with the ffbitext() function above, srcPB points to the FIRST (most
  502. ** significant) byte of the value to test the nth bit of.
  503. */
  504. unsigned char
  505. #ifdef PROTOTYPES
  506. fftstbit(unsigned char *srcPB, int srclenN, int nbitN)
  507. #else
  508. fftstbit(srcPB, srclenN, nbitN)
  509. unsigned char *srcPB;
  510. int srclenN;
  511. int nbitN;
  512. #endif
  513. {
  514.     int stbyteN, stbitN;
  515.  
  516.     /* Convert the source pointer from most significant
  517.      * byte pointer format to least signficant byte pointer format. */
  518.     srcPB += (srclenN - 1);
  519.  
  520.     /* Determine where the bit to set is located at. */
  521.     stbyteN = nbitN >> 3;
  522.     stbitN = nbitN & 0x7;
  523.  
  524.     /* Point at byte containing bit. */
  525.     srcPB -= stbyteN;
  526.  
  527.     /* Test the appropriate bit */
  528.     if ((*srcPB & ffsetmaskAB[stbitN]) == 0)
  529.     return(0);
  530.  
  531.     return(1);
  532. }
  533.  
  534. /*
  535. ** Function:    int fftotlen(int expbitN, int fracbitN)
  536. **
  537. ** Calculate the total byte length of a floating point number given its
  538. ** exponent bit length and its mantissa exponent length.
  539. */
  540. int
  541. #ifdef PROTOTYPES
  542. fftotlen(int expbitN, int fracbitN)
  543. #else
  544. fftotlen(expbitN, fracbitN)
  545. int expbitN;
  546. int fracbitN;
  547. #endif
  548. {
  549.     int totalenN;
  550.  
  551.     totalenN = (((expbitN + fracbitN + 1) % 8) == 0) ? 0 : 1;
  552.     totalenN += ((expbitN + fracbitN + 1) >> 3);
  553.     return(totalenN);
  554. }
  555.  
  556. /*
  557. ** Function:    int ffexplen(int expbitN)
  558. **
  559. ** Calculate the total byte length of the exponent field of a floating point
  560. ** number given its exponent bit length.
  561. */
  562. int
  563. #ifdef PROTOTYPES
  564. ffexplen(int expbitN)
  565. #else
  566. ffexplen(expbitN)
  567. int expbitN;
  568. #endif
  569. {
  570.     int expbyteN;
  571.  
  572.     expbyteN = ((expbitN % 8) == 0) ? 0 : 1;
  573.     expbyteN += (expbitN >> 3);
  574.     return(expbyteN);
  575. }
  576.  
  577. /*
  578. ** Function:    int ffraclen(int fracbitN)
  579. **
  580. ** Calculate the total byte length of the mantissa field of a floating point
  581. ** number given its mantissa bit length.
  582. */
  583. int
  584. #ifdef PROTOTYPES
  585. ffraclen(int fracbitN)
  586. #else
  587. ffraclen(fracbitN)
  588. int fracbitN;
  589. #endif
  590. {
  591.     int fracbyteN;
  592.  
  593.     fracbyteN = (((fracbitN + 1) % 8) == 0) ? 0 : 1;
  594.     fracbyteN += ((fracbitN + 1) >> 3);
  595.     return(fracbyteN);
  596. }
  597.  
  598. /*
  599. ** Function:    void ffgenbias(int expbyteN, int expbitN)
  600. **
  601. ** Generate exponent bias values.
  602. */
  603. void
  604. #ifdef PROTOTYPES
  605. ffgenbias(unsigned char *expbiasPB, int expbyteN, int expbitN)
  606. #else
  607. ffgenbias(expbiasPB, expbyteN, expbitN)
  608. unsigned char *expbiasPB;
  609. int expbyteN;
  610. int expbitN;
  611. #endif
  612. {
  613.     int i;
  614.  
  615.     *(expbiasPB + (expbyteN - 1)) = 1;        /* Set the ls bit to 1 */
  616.     for (i = 0; i < (expbitN - 2); i++)
  617.     {
  618.     ushftlm( expbiasPB, expbyteN );
  619.     *(expbiasPB + (expbyteN - 1)) |= 1;    /* Set next ls bit to 1 */
  620.     }
  621.     return;
  622. }
  623.  
  624. /*
  625. ** Function:    void ffextall(unsigned char *fltPB, int totalenN,
  626. **                  int fracbitN, int fracbyteN, int expbitN,
  627. **                  int expbyteN, unsigned char *fltfracPB,
  628. **                  unsigned char *fltexpPB,
  629. **                  unsigned char *fltsignPB)
  630. **
  631. ** Extract the mantissa, exponent, and sign from the floating point number
  632. ** pointed to by by fltPB.
  633. **
  634. ** totalenN gives the total byte length of the floating point number.
  635. **
  636. ** fracbitN and fracbyteN give the total bit and byte length of the mantissa
  637. ** portion respectively.
  638. **
  639. ** expbitN and expbyteN give the total bit and byte length of the exponent
  640. ** portion respectively.
  641. **
  642. ** fltfracPB, fltexpPB, and fltsignPB point to where the extracted mantissa,
  643. ** exponent, and sign values are to be put.
  644. **
  645. ** Memory for each extracted value must be allocated prior to calling this
  646. ** routine.
  647. */
  648. void
  649. #ifdef PROTOTYPES
  650. ffextall(unsigned char *fltPB, int totalenN, int fracbitN, int fracbyteN,
  651.      int expbitN, int expbyteN, unsigned char *fltfracPB,
  652.      unsigned char *fltexpPB, unsigned char *fltsignPB)
  653. #else
  654. ffextall(fltPB, totalenN, fracbitN, fracbyteN, expbitN, expbyteN, fltfracPB,
  655.      fltexpPB, fltsignPB)
  656. unsigned char *fltPB;
  657. int totalenN;
  658. int fracbitN;
  659. int fracbyteN;
  660. int expbitN;
  661. int expbyteN;
  662. unsigned char *fltfracPB;
  663. unsigned char *fltexpPB;
  664. unsigned char *fltsignPB;
  665. #endif
  666. {
  667.     /* Isolate the mantissa. */
  668.     ffbitext(fltPB, totalenN, 0, fracbitN, fltfracPB, fracbyteN);
  669.     /* Isolate the exponent. */
  670.     ffbitext(fltPB, totalenN, fracbitN, expbitN, fltexpPB, expbyteN);
  671.     /* Isolate the sign, note that only one byte is required for this. */
  672.     ffbitext(fltPB, totalenN, (fracbitN + expbitN), 1, fltsignPB, 1);
  673.     /* Set the implied most significant mantissa bit to 1 */
  674.     ffbitset(fltfracPB, fracbyteN, fracbitN);
  675.     return;
  676. }
  677.