Changeset 8511 in project


Ignore:
Timestamp:
02/17/08 07:09:49 (12 years ago)
Author:
Kon Lovett
Message:

Updated doc.

Location:
release/3/mathh/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • release/3/mathh/trunk/bitwise-extras.scm

    r8510 r8511  
    255255     "bad argument type - not an non-negative integer" obj) ) )
    256256
    257 (define-inline (check-<= loc obj1 obj2)
    258   (when (< obj2 obj1)
     257(define-inline (check-<= loc num1 num2)
     258  (when (< num2 num1)
    259259    (##sys#signal-hook #:type-error loc
    260      "bad argument type - not a valid non-negative integer range" obj1 obj2) ) )
     260     "bad argument type - not a valid open interval" num1 num2) ) )
    261261
    262262;;;
     
    264264(define-inline (%boolean->bit b)
    265265  (if b #b1 #b0) )
     266
     267(define %bitwise-if
     268  (foreign-lambda* unsigned-int ((integer mask) (integer t) (integer f))
     269   "return (BITS_MERGE( mask, t, f ));"))
     270
     271(define %bitwise-if-not
     272  (foreign-lambda* unsigned-int ((integer mask) (integer t) (integer f))
     273   "return (BITS_MERGE_NOT( mask, t, f ));"))
     274
     275(define %bitwise-test?
     276  (foreign-lambda* bool ((integer a) (integer b))
     277   "return (BITS_TEST( a, b ));"))
     278
     279(define %bitwise-bit-count
     280  (foreign-lambda* unsigned-int ((integer value))
     281   "return ((0 < value)\n"
     282   "            ? C_uword_bits( (C_uword) value )\n"
     283   "            : ((0 == value) ? 0 : /*~*/ C_uword_bits( (C_uword) (~ value) )));"))
     284
     285(define %bitwise-length
     286  (foreign-lambda* unsigned-int ((integer value))
     287   "return (C_uword_log2( (C_uword) ((value < 0) ? ~ value : value ) ));"))
     288
     289(define %bitwise-first-bit-set
     290  (foreign-lambda* int ((integer value))
     291   "return (C_UWORD_LOG2_FACTORS( (C_uword) value ));"))
     292
     293(define %bitwise-last-bit-set
     294  (foreign-lambda* unsigned-int ((integer value))
     295   "return (C_uword_log2( (C_uword) value ));"))
     296
     297(define %bitwise-bit-set?
     298  (foreign-lambda* bool ((integer value) (unsigned-int index))
     299   "return (BIT_TEST( value, index ));"))
     300
     301(define %bitwise-copy-bit
     302  (foreign-lambda* integer ((integer to) (unsigned-int start) (unsigned-int bit))
     303   "return (BIT_COPY( to, start, bit ));"))
     304
     305(define %bitwise-bit-field
     306  (foreign-lambda* integer ((integer value) (unsigned-int start) (unsigned-int end))
     307   "return (BITS( value, start, end ));"))
     308
     309(define %bitwise-copy-bit-field
     310  (foreign-lambda* integer ((integer to) (unsigned-int start) (unsigned-int end) (integer from))
     311   "return (BITS_COPY( to, start, end, from ));"))
    266312
    267313#; ; Doesn't work
     
    285331   "C_uword fld = BITS( value, start, end );\n"
    286332   "return (BITS_COPY( value, start, end, ((fld << cnt) ^ (fld >> (wid - cnt))) ));"))
    287 
    288 (define %bitwise-if
    289   (foreign-lambda* unsigned-int ((integer mask) (integer t) (integer f))
    290    "return (BITS_MERGE( mask, t, f ));"))
    291 
    292 (define %bitwise-if-not
    293   (foreign-lambda* unsigned-int ((integer mask) (integer t) (integer f))
    294    "return (BITS_MERGE_NOT( mask, t, f ));"))
    295 
    296 (define %bitwise-test?
    297   (foreign-lambda* bool ((integer a) (integer b))
    298    "return (BITS_TEST( a, b ));"))
    299 
    300 (define %bitwise-bit-count
    301   (foreign-lambda* unsigned-int ((integer value))
    302    "return ((0 < value)\n"
    303    "            ? C_uword_bits( (C_uword) value )\n"
    304    "            : ((0 == value) ? 0 : /*~*/ C_uword_bits( (C_uword) (~ value) )));"))
    305 
    306 (define %bitwise-length
    307   (foreign-lambda* unsigned-int ((integer value))
    308    "return (C_uword_log2( (C_uword) ((value < 0) ? ~ value : value ) ));"))
    309 
    310 (define %bitwise-first-bit-set
    311   (foreign-lambda* int ((integer value))
    312    "return (C_UWORD_LOG2_FACTORS( (C_uword) value ));"))
    313 
    314 (define %bitwise-last-bit-set
    315   (foreign-lambda* unsigned-int ((integer value))
    316    "return (C_uword_log2( (C_uword) value ));"))
    317 
    318 (define %bitwise-bit-set?
    319   (foreign-lambda* bool ((integer value) (unsigned-int index))
    320    "return (BIT_TEST( value, index ));"))
    321 
    322 (define %bitwise-copy-bit
    323   (foreign-lambda* integer ((integer to) (unsigned-int start) (unsigned-int bit))
    324    "return (BIT_COPY( to, start, bit ));"))
    325 
    326 (define %bitwise-bit-field
    327   (foreign-lambda* integer ((integer value) (unsigned-int start) (unsigned-int end))
    328    "return (BITS( value, start, end ));"))
    329 
    330 (define %bitwise-copy-bit-field
    331   (foreign-lambda* integer ((integer to) (unsigned-int start) (unsigned-int end) (integer from))
    332    "return (BITS_COPY( to, start, end, from ));"))
    333333
    334334#; ; TBD
  • release/3/mathh/trunk/doc.scm

    r8510 r8511  
    1010    (name "mathh")
    1111    (description
    12       (p "Provides access to ISO C math functions & constants in " (code
    13       "<math.h>") " that are not defined by Chicken."))
     12      (p "Provides access to ISO C math functions in " (code "<math.h>") " "
     13      "that are not defined by Chicken.")
     14      (p "Also supplies " (code "<float.h>") " constants, common derived constants, and "
     15      "limits for Chicken numeric types.") )
    1416
    1517    (author "John Cowan and Kon Lovett")
     
    9698            (describe negative-zero "")
    9799            (describe unclassified "")) )
    98       )
    99 
    100       #;
    101       (subsection "Fixnum Procedures"
    102 
    103         (usage "(require-extension fixnum-extras)")
    104 
    105         (procedure "(fxlog2 N)"
    106           (p "Returns the ceiling of log2 of the " (tt "N") " fixnum."))
    107 
    108         (procedure "(fx1bits N)"
    109           (p "Returns the number of one bits in the " (tt "N") " fixnum."))
    110 
    111         (procedure "(fx0bits N)"
    112           (p "Returns the number of zero bits in the " (tt "N") " fixnum."))
    113 
    114         (procedure "(bitwise-count-bits N [FLAG #t])"
    115           (p "Returns the number of " (tt "FLAG") " bits in the integer"
    116           (tt "N") "."))
    117       )
    118 
    119       #;
    120       (subsection "Bitwise Procedures"
    121 
    122         (usage "(require-extension bitwise-extras)")
    123 
    124100      )
    125101
     
    243219          (describe ZETA3 "theta(3)") )
    244220      )
     221
     222      #;
     223      (subsection "Fixnum Procedures"
     224
     225        (usage "(require-extension fixnum-extras)")
     226
     227      )
     228
     229      (subsection "Bitwise Procedures"
     230
     231        (usage "(require-extension bitwise-extras)")
     232
     233        (p "Unchecked variants of the following procedures are supplied, named "
     234        "as the checked version but with a \"%\" prefix.")
     235
     236                                (procedure "(boolean->bit OBJECT)"
     237                                        (p "Returns " (code "1") " for truth values and " (code "0") " for "
     238                                        "false or zero.") )
     239
     240                                (procedure "(bitwise-if MASK TRUE FALSE)"
     241                                        (p "Merge under mask.") )
     242
     243                                (procedure "(bitwise-if-not MASK TRUE FALSE)"
     244                                        (p "Merge under not mask.") )
     245
     246                                (procedure "(bitwise-test? VALUE1 VALUE2)"
     247                                        (p "Any bits set in both " (tt "VALUE1") " and " (tt "VALUE2") "?") )
     248
     249                                (procedure "(bitwise-bit-count VALUE)"
     250                                        (p "Count of set bits.") )
     251
     252                                (procedure "(bitwise-length VALUE)"
     253                                        (p "Minimum number of bits to represent.") )
     254
     255                                (procedure "(bitwise-first-bit-set VALUE)"
     256                                        (p "Least significant bit set.") )
     257
     258                                (procedure "(bitwise-last-bit-set VALUE)"
     259                                        (p "Most significant bit set.") )
     260
     261                                (procedure "(bitwise-bit-set? VALUE INDEX)"
     262                                        (p "Specific bit set?") )
     263
     264                                (procedure "(bitwise-copy-bit TO START BIT)"
     265                                        (p "Set bit.") )
     266
     267                                (procedure "(bitwise-bit-field VALUE START END)"
     268                                        (p "Get bits.") )
     269
     270                                (procedure "(bitwise-copy-bit-field TO START END FROM)"
     271                                        (p "Set bits.") )
     272
     273                                (procedure "(bitwise-rotate-bit-field VALUE START END COUNT)"
     274                                        (p "Rotate bits.") )
     275
     276                                (procedure "(bitwise-reverse VALUE COUNT)"
     277                                        (p "Reverse low-order bits.") )
     278
     279                                (procedure "(bitwise-reverse-bit-field VALUE START END)"
     280                                        (p "Reverse bits.") )
     281
     282                                (procedure "(bitwise-list->integer LIST)"
     283                                        (p "Converts list of boolean, least-significant to most-significant, to integer.") )
     284
     285                                (procedure "(bitwise-integer->list VALUE [LENGTH])"
     286                                        (p "Converts integer to list of boolean, least-significant to most-significant.") )
     287      )
    245288    )
    246289
  • release/3/mathh/trunk/mathh.html

    r8510 r8511  
    152152<div class="section">
    153153<h3>Description</h3>
    154 <p>Provides access to ISO C math functions &amp; constants in <code>&lt;math.h&gt;</code> that are not defined by Chicken.</p></div>
     154<p>Provides access to ISO C math functions in <code>&lt;math.h&gt;</code> that are not defined by Chicken.</p>
     155<p>Also supplies <code>&lt;float.h&gt;</code> constants, common derived constants, and limits for Chicken numeric types.</p></div>
    155156<div class="section">
    156157<h3>Author</h3>John Cowan and Kon Lovett</div>
     
    573574<tr>
    574575<td class="symbol">ZETA3</td>
    575 <td>theta(3)</td></tr></table></div></div>
     576<td>theta(3)</td></tr></table></div>
     577<div class="subsection">
     578<h4>Bitwise Procedures</h4>
     579<div class="section">
     580<h3>Usage</h3>(require-extension bitwise-extras)</div>
     581<p>Unchecked variants of the following procedures are supplied, named as the checked version but with a &quot;%&quot; prefix.</p>
     582<dt class="definition"><strong>procedure:</strong> (boolean-&gt;bit OBJECT)</dt>
     583<dd>
     584<p>Returns <code>1</code> for truth values and <code>0</code> for false or zero.</p></dd>
     585<dt class="definition"><strong>procedure:</strong> (bitwise-if MASK TRUE FALSE)</dt>
     586<dd>
     587<p>Merge under mask.</p></dd>
     588<dt class="definition"><strong>procedure:</strong> (bitwise-if-not MASK TRUE FALSE)</dt>
     589<dd>
     590<p>Merge under not mask.</p></dd>
     591<dt class="definition"><strong>procedure:</strong> (bitwise-test? VALUE1 VALUE2)</dt>
     592<dd>
     593<p>Any bits set in both <tt>VALUE1</tt> and <tt>VALUE2</tt>?</p></dd>
     594<dt class="definition"><strong>procedure:</strong> (bitwise-bit-count VALUE)</dt>
     595<dd>
     596<p>Count of set bits.</p></dd>
     597<dt class="definition"><strong>procedure:</strong> (bitwise-length VALUE)</dt>
     598<dd>
     599<p>Minimum number of bits to represent.</p></dd>
     600<dt class="definition"><strong>procedure:</strong> (bitwise-first-bit-set VALUE)</dt>
     601<dd>
     602<p>Least significant bit set.</p></dd>
     603<dt class="definition"><strong>procedure:</strong> (bitwise-last-bit-set VALUE)</dt>
     604<dd>
     605<p>Most significant bit set.</p></dd>
     606<dt class="definition"><strong>procedure:</strong> (bitwise-bit-set? VALUE INDEX)</dt>
     607<dd>
     608<p>Specific bit set?</p></dd>
     609<dt class="definition"><strong>procedure:</strong> (bitwise-copy-bit TO START BIT)</dt>
     610<dd>
     611<p>Set bit.</p></dd>
     612<dt class="definition"><strong>procedure:</strong> (bitwise-bit-field VALUE START END)</dt>
     613<dd>
     614<p>Get bits.</p></dd>
     615<dt class="definition"><strong>procedure:</strong> (bitwise-copy-bit-field TO START END FROM)</dt>
     616<dd>
     617<p>Set bits.</p></dd>
     618<dt class="definition"><strong>procedure:</strong> (bitwise-rotate-bit-field VALUE START END COUNT)</dt>
     619<dd>
     620<p>Rotate bits.</p></dd>
     621<dt class="definition"><strong>procedure:</strong> (bitwise-reverse VALUE COUNT)</dt>
     622<dd>
     623<p>Reverse low-order bits.</p></dd>
     624<dt class="definition"><strong>procedure:</strong> (bitwise-reverse-bit-field VALUE START END)</dt>
     625<dd>
     626<p>Reverse bits.</p></dd>
     627<dt class="definition"><strong>procedure:</strong> (bitwise-list-&gt;integer LIST)</dt>
     628<dd>
     629<p>List of boolean to integer.</p></dd>
     630<dt class="definition"><strong>procedure:</strong> (bitwise-integer-&gt;list VALUE [LENGTH])</dt>
     631<dd>
     632<p>Integer to list of boolean, least-significant to most-significant.</p></dd></div></div>
    576633<div class="section">
    577634<h3>Version</h3>
  • release/3/mathh/trunk/mathh.meta

    r8510 r8511  
    33(
    44 (egg "mathh.egg")
    5  (synopsis "Some ISO C math functions and more")
     5 (synopsis "ISO C math functions and constants")
    66 (category math)
    7  (license "Public domain")
     7 (license "Public Domain")
    88 (author "John Cowan and Kon Lovett")
    99 (eggdoc "doc.scm")
     
    1717        "mathh-fpclass.scm"
    1818        "bitwise-extras.scm"
    19         #;
    20         "fixnum-extras.scm"
     19        ;;"fixnum-extras.scm"
    2120        "mathh.setup"
    2221        "mathh.html") )
  • release/3/mathh/trunk/tests/mathh-test.scm

    r8510 r8511  
    1717;;;
    1818
    19 #|
    20 
    21 (define (logical:ash-4 x)
    22   (if (negative? x)
    23       (+ -1 (quotient (+ 1 x) 16))
    24       (quotient x 16)))
    25 
    26 (define ilength
    27   (letrec ((intlen (lambda (n tot)
    28                      (case n
    29                        ((0 -1) (+ 0 tot))
    30                        ((1 -2) (+ 1 tot))
    31                        ((2 3 -3 -4) (+ 2 tot))
    32                        ((4 5 6 7 -5 -6 -7 -8) (+ 3 tot))
    33                        (else (intlen (logical:ash-4 n) (+ 4 tot)))))))
    34     (lambda (n) (intlen n 0))))
    35 
    36 ;; log2( n ) for positive n
    37 (define (ilog2 n)
    38   (let loop ([v n] [r 0])
    39     (if (= 0 v)
    40         r
    41         (loop (arithmetic-shift v -1) (+ r 1)) ) ) )
    42 
    43 (define (ilog2-factors n)
    44   (+ -1 (ilength (bitwise-and n (- n)))))
    45 
    46 ;; 2 ^ log2( n ) for positive n
    47 (define (ipow2log2 n)
    48   (arithmetic-shift 2 (- (bitwise-last-bit-set n) 1))
    49   #;
    50   (let loop ([r 1])
    51     (if (< r n)
    52         (loop (arithmetic-shift r 1))
    53         r ) ) )
    54 |#
    55 
    56 #|
    5719(define-test mathh-iso-c-test "ISO C Functions"
    5820
     
    10769)
    10870
     71#;
    10972(define-test mathh-fixnum-test "Fixnum Functions"
    11073)
    111 |#
    11274
    11375(define-test mathh-bitwise-test "Bitwise Functions"
Note: See TracChangeset for help on using the changeset viewer.