~ chicken-core (master) /manual/Module (chicken fixnum)
Trap1[[tags: manual]]2[[toc:]]34== Module (chicken fixnum)56Because CHICKEN supports a full numeric tower, operations can7sometimes incur a substantial overhead to simply detect the type of numbers8you're passing in. When you know you're definitely dealing only with9fixnums, you can choose to use fixnum-specific operations to avoid10this overhead.1112This is purely a performance hack. You might want to consider adding13[[Types|type annotations]] instead, this often gives the same14performance boost without having to rewrite all numeric operators in15your code.161718=== Arithmetic fixnum operations1920<procedure>(fx+ N1 N2)</procedure>21<procedure>(fx- N1 N2)</procedure>22<procedure>(fx* N1 N2)</procedure>23<procedure>(fx/ N1 N2)</procedure>24<procedure>(fxmod N1 N2)</procedure>25<procedure>(fxrem N1 N2)</procedure>26<procedure>(fxneg N)</procedure>27<procedure>(fxlen N)</procedure>28<procedure>(fxmin N1 N2)</procedure>29<procedure>(fxmax N1 N2)</procedure>30<procedure>(fxand N1 N2)</procedure>31<procedure>(fxior N1 N2)</procedure>32<procedure>(fxxor N1 N2)</procedure>33<procedure>(fxnot N)</procedure>34<procedure>(fxshl N1 N2)</procedure>35<procedure>(fxshr N1 N2)</procedure>36<procedure>(fxgcd N1 N2)</procedure>3738{{fx+}} and friends are arithmetic fixnum operations. These procedures do not39check their arguments, so non-fixnum parameters will result in incorrect40results. {{fxneg}} negates its argument, {{fxlen}} returns the integer length41in bits.4243On division by zero, {{fx/}}, {{fxmod}} and {{fxrem}} signal a44condition of kind {{(exn arithmetic)}}.4546{{fxshl}} and {{fxshr}} perform arithmetic shift left and right,47respectively.4849=== Overflow-aware fixnum operations5051<procedure>(fx+? N1 N2)</procedure>52<procedure>(fx-? N1 N2)</procedure>53<procedure>(fx*? N1 N2)</procedure>54<procedure>(fx/? N1 N2)</procedure>5556These procedures behave similarly to their standard counterparts with57the exception that {{#f}} is returned if an argument is not a fixnum58or the result of the operation overflows.5960Chaining of such procedures is well-defined and causes the overflow61error to be propagated.6263=== Fixnum comparison and predicates6465<procedure>(fxodd? N)</procedure>66<procedure>(fxeven? N)</procedure>67<procedure>(fx= N1 N2)</procedure>68<procedure>(fx> N1 N2)</procedure>69<procedure>(fx< N1 N2)</procedure>70<procedure>(fx>= N1 N2)</procedure>71<procedure>(fx<= N1 N2)</procedure>7273Comparison of fixnums and predicates on them.7475=== Fixnum limits7677<constant>most-positive-fixnum</constant><br>78<constant>most-negative-fixnum</constant><br>79<constant>fixnum-bits</constant><br>80<constant>fixnum-precision</constant><br>8182Platform-specific fixnum limits.8384---85Previous: [[Module (chicken file posix)]]8687Next: [[Module (chicken flonum)]]