1367 |
|
|
1368 |
SCM_DEFINE (scm_ash, "ash", 2, 0, 0, |
SCM_DEFINE (scm_ash, "ash", 2, 0, 0, |
1369 |
(SCM n, SCM cnt), |
(SCM n, SCM cnt), |
1370 |
"The function ash performs an arithmetic shift left by @var{cnt}\n" |
"Return @var{n} shifted left by @var{cnt} bits, or shifted right\n" |
1371 |
"bits (or shift right, if @var{cnt} is negative). 'Arithmetic'\n" |
"if @var{cnt} is negative. This is an ``arithmetic'' shift.\n" |
|
"means, that the function does not guarantee to keep the bit\n" |
|
|
"structure of @var{n}, but rather guarantees that the result\n" |
|
|
"will always be rounded towards minus infinity. Therefore, the\n" |
|
|
"results of ash and a corresponding bitwise shift will differ if\n" |
|
|
"@var{n} is negative.\n" |
|
1372 |
"\n" |
"\n" |
1373 |
"Formally, the function returns an integer equivalent to\n" |
"This is effectively a multiplication by 2^@var{cnt}}, and when\n" |
1374 |
"@code{(inexact->exact (floor (* @var{n} (expt 2 @var{cnt}))))}.\n" |
"@var{cnt} is negative it's a division, rounded towards negative\n" |
1375 |
|
"infinity. (Note that this is not the same rounding as\n" |
1376 |
|
"@code{quotient} does.)\n" |
1377 |
|
"\n" |
1378 |
|
"With @var{n} viewed as an infinite precision twos complement,\n" |
1379 |
|
"@code{ash} means a left shift introducing zero bits, or a right\n" |
1380 |
|
"shift dropping bits.\n" |
1381 |
"\n" |
"\n" |
1382 |
"@lisp\n" |
"@lisp\n" |
1383 |
"(number->string (ash #b1 3) 2) @result{} \"1000\"\n" |
"(number->string (ash #b1 3) 2) @result{} \"1000\"\n" |
1384 |
"(number->string (ash #b1010 -1) 2) @result{} \"101\"\n" |
"(number->string (ash #b1010 -1) 2) @result{} \"101\"\n" |
1385 |
|
"\n" |
1386 |
|
";; -23 is bits ...11101001, -6 is bits ...111010\n" |
1387 |
|
"(ash -23 -2) @result{} -6\n" |
1388 |
"@end lisp") |
"@end lisp") |
1389 |
#define FUNC_NAME s_scm_ash |
#define FUNC_NAME s_scm_ash |
1390 |
{ |
{ |