~ 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>(fxmin N1 N2)</procedure>28<procedure>(fxmax N1 N2)</procedure>29<procedure>(fxand N1 N2)</procedure>30<procedure>(fxior N1 N2)</procedure>31<procedure>(fxxor N1 N2)</procedure>32<procedure>(fxnot N)</procedure>33<procedure>(fxshl N1 N2)</procedure>34<procedure>(fxshr N1 N2)</procedure>35<procedure>(fxgcd N1 N2)</procedure>3637{{fx+}} and friends are arithmetic fixnum operations. These procedures do not38check their arguments, so non-fixnum parameters will result in incorrect39results. {{fxneg}} negates its argument.4041On division by zero, {{fx/}}, {{fxmod}} and {{fxrem}} signal a42condition of kind {{(exn arithmetic)}}.4344{{fxshl}} and {{fxshr}} perform arithmetic shift left and right,45respectively.4647=== Overflow-aware fixnum operations4849<procedure>(fx+? N1 N2)</procedure>50<procedure>(fx-? N1 N2)</procedure>51<procedure>(fx*? N1 N2)</procedure>52<procedure>(fx/? N1 N2)</procedure>5354These procedures behave similarly to their standard counterparts with55the exception that {{#f}} is returned if an argument is not a fixnum56or the result of the operation overflows.5758Chaining of such procedures is well-defined and causes the overflow59error to be propagated.6061=== Fixnum comparison and predicates6263<procedure>(fxodd? N)</procedure>64<procedure>(fxeven? N)</procedure>65<procedure>(fx= N1 N2)</procedure>66<procedure>(fx> N1 N2)</procedure>67<procedure>(fx< N1 N2)</procedure>68<procedure>(fx>= N1 N2)</procedure>69<procedure>(fx<= N1 N2)</procedure>7071Comparison of fixnums and predicates on them.7273=== Fixnum limits7475<constant>most-positive-fixnum</constant><br>76<constant>most-negative-fixnum</constant><br>77<constant>fixnum-bits</constant><br>78<constant>fixnum-precision</constant><br>7980Platform-specific fixnum limits.8182---83Previous: [[Module (chicken file posix)]]8485Next: [[Module (chicken flonum)]]