# Differences

This shows you the differences between two versions of the page.

 cl:functions:ash [2019/09/14 05:00] cl:functions:ash [2019/09/20 08:00] (current) Line 1: Line 1: + ====== Function ASH ====== + + ====Syntax==== + * **ash** //integer count// → //​shifted-integer//​ + + ====Arguments and Values==== + * //integer// - an //​[[CL:​Glossary:​integer]]//​. + * //count// - an //​[[CL:​Glossary:​integer]]//​. + * //​shifted-integer//​ - an //​[[CL:​Glossary:​integer]]//​. + + ====Description==== + **ash** performs the arithmetic shift operation on the binary representation of //​integer//,​ which is treated as if it were binary. + + **ash** shifts //integer// arithmetically left by //count// bit positions if //count// is positive, or right //count// bit positions if //count// is negative. The shifted value of the same sign as //integer// is returned. + + Mathematically speaking, **ash** performs the computation ''​floor(integer * 2<​sup>//​count//​)''​. + + Logically, **ash** moves all of the bits in //integer// to the left, adding zero-bits at the right, or moves them to the right, discarding bits. + + **ash** is defined to behave as if //integer// were represented in two's complement form, regardless of how //​[[CL:​Glossary:​integers]]//​ are represented internally. ​ + + ====Examples==== ​ + <​blockquote> ​ + (ash 16 1) 32 + (ash 16 0) 16 + (ash 16 -1) 8 + (ash -100000000000000000000000000000000 -100) <​r>​-79 + ​ + + ====Affected By==== + None. + + ====Exceptional Situations==== + Should signal an error of type type-error if //integer// is not an //​[[CL:​Glossary:​integer]]//​. Should signal an error of type type-error if //count// is not an //​[[CL:​Glossary:​integer]]//​. Might signal **[[CL:​Types:​arithmetic-error]]**. + + ====See Also==== + None. + + ====Notes==== + <​blockquote> ​ + ([[CL:​Functions:​logbitp]] //j// (ash //n// //​k//​)) ​ + ≡ ([[CL:​Macros:​and]] ([[CL:​Macros:​not-less|>​=]] //j// //​k//​) ​ + ​([[CL:​Functions:​logbitp]] (- //j// //k//) //​n//​)) ​ + ​ +