Mercurial > hg > xemacs-beta
comparison src/floatfns.c @ 5252:378a34562cbe
Fix style, documentation for rounding functions and multiple values.
src/ChangeLog addition:
2010-08-30 Aidan Kehoe <kehoea@parhasard.net>
* floatfns.c (ceiling_one_mundane_arg, floor_one_mundane_arg)
(round_one_mundane_arg, truncate_one_mundane_arg):
INTEGERP is always available, no need to wrap calls to it with
#ifdef HAVE_BIGNUM.
(Fceiling, Ffloor, Fround, Ftruncate, Ffceiling, Fffloor)
(Ffround, Fftruncate):
Correct some code formatting here.
* doprnt.c (emacs_doprnt_1):
Remove some needless #ifdef WITH_NUMBER_TYPES, now number.h is
always #included.
man/ChangeLog addition:
2010-08-30 Aidan Kehoe <kehoea@parhasard.net>
* lispref/eval.texi (Evaluation, Multiple values):
Document our implementation of multiple values; point the reader
to the CLTL or the Hyperspec for details of exactly when values
are discarded.
* lispref/numbers.texi (Numeric Conversions): Document the
optional DIVISOR arguments to the rounding functions, and
document that they all return multiple values.
(Rounding Operations): Ditto.
* cl.texi (Multiple Values):
Document that we've moved the multiple values implementation to
core code, and cross-reference to the Lispref.
(Numerical Functions): The various rounding functions are now
identical to the built-in rounding functions, with the exception
that they return lists, not multiple values; document this.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Mon, 30 Aug 2010 15:23:42 +0100 |
parents | 71ee43b8a74d |
children | 2a7b6ddb8063 308d34e9f07d |
comparison
equal
deleted
inserted
replaced
5251:b0ba3598beb1 | 5252:378a34562cbe |
---|---|
1298 } | 1298 } |
1299 #endif | 1299 #endif |
1300 } | 1300 } |
1301 else | 1301 else |
1302 { | 1302 { |
1303 #ifdef HAVE_BIGNUM | |
1304 if (INTEGERP (number)) | 1303 if (INTEGERP (number)) |
1305 #else | |
1306 if (INTP (number)) | |
1307 #endif | |
1308 { | 1304 { |
1309 return values2 (number, Qzero); | 1305 return values2 (number, Qzero); |
1310 } | 1306 } |
1311 } | 1307 } |
1312 | 1308 |
1564 | 1560 |
1565 static Lisp_Object | 1561 static Lisp_Object |
1566 floor_one_mundane_arg (Lisp_Object number, Lisp_Object divisor, | 1562 floor_one_mundane_arg (Lisp_Object number, Lisp_Object divisor, |
1567 int return_float) | 1563 int return_float) |
1568 { | 1564 { |
1569 #ifdef HAVE_BIGNUM | |
1570 if (INTEGERP (number)) | 1565 if (INTEGERP (number)) |
1571 #else | |
1572 if (INTP (number)) | |
1573 #endif | |
1574 { | 1566 { |
1575 if (return_float) | 1567 if (return_float) |
1576 { | 1568 { |
1577 return values2 (make_float (extract_float (number)), Qzero); | 1569 return values2 (make_float (extract_float (number)), Qzero); |
1578 } | 1570 } |
1969 | 1961 |
1970 static Lisp_Object | 1962 static Lisp_Object |
1971 round_one_mundane_arg (Lisp_Object number, Lisp_Object divisor, | 1963 round_one_mundane_arg (Lisp_Object number, Lisp_Object divisor, |
1972 int return_float) | 1964 int return_float) |
1973 { | 1965 { |
1974 #ifdef HAVE_BIGNUM | |
1975 if (INTEGERP (number)) | 1966 if (INTEGERP (number)) |
1976 #else | |
1977 if (INTP (number)) | |
1978 #endif | |
1979 { | 1967 { |
1980 if (return_float) | 1968 if (return_float) |
1981 { | 1969 { |
1982 return values2 (make_float (extract_float (number)), Qzero); | 1970 return values2 (make_float (extract_float (number)), Qzero); |
1983 } | 1971 } |
2256 | 2244 |
2257 static Lisp_Object | 2245 static Lisp_Object |
2258 truncate_one_mundane_arg (Lisp_Object number, Lisp_Object divisor, | 2246 truncate_one_mundane_arg (Lisp_Object number, Lisp_Object divisor, |
2259 int return_float) | 2247 int return_float) |
2260 { | 2248 { |
2261 #ifdef HAVE_BIGNUM | |
2262 if (INTEGERP (number)) | 2249 if (INTEGERP (number)) |
2263 #else | |
2264 if (INTP (number)) | |
2265 #endif | |
2266 { | 2250 { |
2267 if (return_float) | 2251 if (return_float) |
2268 { | 2252 { |
2269 return values2 (make_float (extract_float (number)), Qzero); | 2253 return values2 (make_float (extract_float (number)), Qzero); |
2270 } | 2254 } |
2299 calculation, which will be one minus the fractional part of NUMBER if DIVISOR | 2283 calculation, which will be one minus the fractional part of NUMBER if DIVISOR |
2300 is omitted or one. | 2284 is omitted or one. |
2301 */ | 2285 */ |
2302 (number, divisor)) | 2286 (number, divisor)) |
2303 { | 2287 { |
2304 ROUNDING_CONVERT(ceiling, 0); | 2288 ROUNDING_CONVERT (ceiling, 0); |
2305 } | 2289 } |
2306 | 2290 |
2307 DEFUN ("floor", Ffloor, 1, 2, 0, /* | 2291 DEFUN ("floor", Ffloor, 1, 2, 0, /* |
2308 Return the largest integer no greater than NUMBER. (Round towards -inf.) | 2292 Return the largest integer no greater than NUMBER. (Round towards -inf.) |
2309 With optional second argument DIVISOR, return the largest integer no | 2293 With optional second argument DIVISOR, return the largest integer no |
2314 calculation, which will just be the fractional part if DIVISOR is omitted or | 2298 calculation, which will just be the fractional part if DIVISOR is omitted or |
2315 one. | 2299 one. |
2316 */ | 2300 */ |
2317 (number, divisor)) | 2301 (number, divisor)) |
2318 { | 2302 { |
2319 ROUNDING_CONVERT(floor, 0); | 2303 ROUNDING_CONVERT (floor, 0); |
2320 } | 2304 } |
2321 | 2305 |
2322 DEFUN ("round", Fround, 1, 2, 0, /* | 2306 DEFUN ("round", Fround, 1, 2, 0, /* |
2323 Return the nearest integer to NUMBER. | 2307 Return the nearest integer to NUMBER. |
2324 If NUMBER is exactly halfway between two integers, return the one that | 2308 If NUMBER is exactly halfway between two integers, return the one that |
2331 `multiple-value-bind'. The second returned value is the remainder | 2315 `multiple-value-bind'. The second returned value is the remainder |
2332 in the calculation. | 2316 in the calculation. |
2333 */ | 2317 */ |
2334 (number, divisor)) | 2318 (number, divisor)) |
2335 { | 2319 { |
2336 ROUNDING_CONVERT(round, 0); | 2320 ROUNDING_CONVERT (round, 0); |
2337 } | 2321 } |
2338 | 2322 |
2339 DEFUN ("truncate", Ftruncate, 1, 2, 0, /* | 2323 DEFUN ("truncate", Ftruncate, 1, 2, 0, /* |
2340 Truncate a floating point number to an integer. | 2324 Truncate a floating point number to an integer. |
2341 Rounds the value toward zero. | 2325 Rounds the value toward zero. |
2345 This function returns multiple values; see `multiple-value-call' and | 2329 This function returns multiple values; see `multiple-value-call' and |
2346 `multiple-value-bind'. The second returned value is the remainder. | 2330 `multiple-value-bind'. The second returned value is the remainder. |
2347 */ | 2331 */ |
2348 (number, divisor)) | 2332 (number, divisor)) |
2349 { | 2333 { |
2350 ROUNDING_CONVERT(truncate, 0); | 2334 ROUNDING_CONVERT (truncate, 0); |
2351 } | 2335 } |
2352 | 2336 |
2353 /* Float-rounding functions. */ | 2337 /* Float-rounding functions. */ |
2354 | 2338 |
2355 DEFUN ("fceiling", Ffceiling, 1, 2, 0, /* | 2339 DEFUN ("fceiling", Ffceiling, 1, 2, 0, /* |
2362 This function returns multiple values; the second value is the remainder in | 2346 This function returns multiple values; the second value is the remainder in |
2363 the calculation. | 2347 the calculation. |
2364 */ | 2348 */ |
2365 (number, divisor)) | 2349 (number, divisor)) |
2366 { | 2350 { |
2367 ROUNDING_CONVERT(ceiling, 1); | 2351 ROUNDING_CONVERT (ceiling, 1); |
2368 } | 2352 } |
2369 | 2353 |
2370 DEFUN ("ffloor", Fffloor, 1, 2, 0, /* | 2354 DEFUN ("ffloor", Fffloor, 1, 2, 0, /* |
2371 Return the largest integer no greater than NUMBER, as a float. | 2355 Return the largest integer no greater than NUMBER, as a float. |
2372 \(Round towards -inf.\) | 2356 \(Round towards -inf.\) |
2377 This function returns multiple values; the second value is the remainder in | 2361 This function returns multiple values; the second value is the remainder in |
2378 the calculation. | 2362 the calculation. |
2379 */ | 2363 */ |
2380 (number, divisor)) | 2364 (number, divisor)) |
2381 { | 2365 { |
2382 ROUNDING_CONVERT(floor, 1); | 2366 ROUNDING_CONVERT (floor, 1); |
2383 } | 2367 } |
2384 | 2368 |
2385 DEFUN ("fround", Ffround, 1, 2, 0, /* | 2369 DEFUN ("fround", Ffround, 1, 2, 0, /* |
2386 Return the nearest integer to NUMBER, as a float. | 2370 Return the nearest integer to NUMBER, as a float. |
2387 If NUMBER is exactly halfway between two integers, return the one that is | 2371 If NUMBER is exactly halfway between two integers, return the one that is |
2393 This function returns multiple values; the second value is the remainder in | 2377 This function returns multiple values; the second value is the remainder in |
2394 the calculation. | 2378 the calculation. |
2395 */ | 2379 */ |
2396 (number, divisor)) | 2380 (number, divisor)) |
2397 { | 2381 { |
2398 ROUNDING_CONVERT(round, 1); | 2382 ROUNDING_CONVERT (round, 1); |
2399 } | 2383 } |
2400 | 2384 |
2401 DEFUN ("ftruncate", Fftruncate, 1, 2, 0, /* | 2385 DEFUN ("ftruncate", Fftruncate, 1, 2, 0, /* |
2402 Truncate a floating point number to an integral float value. | 2386 Truncate a floating point number to an integral float value. |
2403 Rounds the value toward zero. | 2387 Rounds the value toward zero. |
2408 This function returns multiple values; the second value is the remainder in | 2392 This function returns multiple values; the second value is the remainder in |
2409 the calculation. | 2393 the calculation. |
2410 */ | 2394 */ |
2411 (number, divisor)) | 2395 (number, divisor)) |
2412 { | 2396 { |
2413 ROUNDING_CONVERT(truncate, 1); | 2397 ROUNDING_CONVERT (truncate, 1); |
2414 } | 2398 } |
2415 | 2399 |
2416 #ifdef FLOAT_CATCH_SIGILL | 2400 #ifdef FLOAT_CATCH_SIGILL |
2417 static SIGTYPE | 2401 static SIGTYPE |
2418 float_error (int signo) | 2402 float_error (int signo) |