diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-06-13 16:35:08 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-06-13 16:35:08 -0300 |
commit | 0beeb4f6fa9ed3f0b92d110c9774a6b50d5690fe (patch) | |
tree | f32fb966b483f31a1ab787ff4c86259b6a3a5f56 /luaconf.h | |
parent | 788b25115715340613d1e7139837a51cd429c000 (diff) | |
download | lua-0beeb4f6fa9ed3f0b92d110c9774a6b50d5690fe.tar.gz lua-0beeb4f6fa9ed3f0b92d110c9774a6b50d5690fe.tar.bz2 lua-0beeb4f6fa9ed3f0b92d110c9774a6b50d5690fe.zip |
configuration of number sizes goes "mainstream"
Diffstat (limited to 'luaconf.h')
-rw-r--r-- | luaconf.h | 140 |
1 files changed, 71 insertions, 69 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: luaconf.h,v 1.179 2013/04/29 17:12:12 roberto Exp roberto $ | 2 | ** $Id: luaconf.h,v 1.181 2013/05/26 13:35:52 roberto Exp roberto $ |
3 | ** Configuration file for Lua | 3 | ** Configuration file for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -376,44 +376,34 @@ | |||
376 | 376 | ||
377 | /* | 377 | /* |
378 | ** {================================================================== | 378 | ** {================================================================== |
379 | @@ LUA_NUMBER is the type of numbers in Lua. | 379 | ** The following definitions set the numeric types for Lua. |
380 | ** CHANGE the following definitions only if you want to build Lua | 380 | ** Lua should work fine with 32-bit or 64-bit integers mixed with |
381 | ** with a number type different from double. You may also need to | 381 | ** 32-bit or 64-bit floats. The usual configurations are 64-bit |
382 | ** change lua_number2int & lua_number2integer. | 382 | ** integers and floats (the default) and 32-bit integers and floats. |
383 | ** =================================================================== | 383 | ** =================================================================== |
384 | */ | 384 | */ |
385 | 385 | ||
386 | #define LUA_NUMBER_DOUBLE | ||
387 | #define LUA_NUMBER double | ||
388 | |||
389 | /* | 386 | /* |
390 | @@ LUAI_UACNUMBER is the result of an 'usual argument conversion' | 387 | @@ LUA_SMALL_INT true makes Lua use a 32-bit integer type |
391 | @* over a number. | 388 | @@ LUA_SMALL_FLOAT true makes Lua use a 32-bit float type |
392 | */ | 389 | */ |
393 | #define LUAI_UACNUMBER double | 390 | #define LUA_SMALL_FLOAT 0 |
391 | #define LUA_SMALL_INT 0 | ||
394 | 392 | ||
395 | 393 | ||
396 | /* | 394 | /* |
395 | @@ LUA_NUMBER is the floating-point type used by Lua. | ||
396 | ** | ||
397 | @@ LUAI_UACNUMBER is the result of an 'usual argument conversion' | ||
398 | @* over a floating number. | ||
399 | ** | ||
397 | @@ LUA_NUMBER_FRMLEN is the length modifier for writing floats. | 400 | @@ LUA_NUMBER_FRMLEN is the length modifier for writing floats. |
398 | @@ LUA_NUMBER_SCAN is the format for reading floats. | 401 | @@ LUA_NUMBER_SCAN is the format for reading floats. |
399 | @@ LUA_NUMBER_FMT is the format for writing floats. | 402 | @@ LUA_NUMBER_FMT is the format for writing floats. |
400 | @@ lua_number2str converts a floats to a string. | 403 | @@ lua_number2str converts a floats to a string. |
401 | @@ LUAI_MAXNUMBER2STR is maximum size of previous conversion. | 404 | ** |
402 | */ | ||
403 | #define LUA_NUMBER_FRMLEN "" | ||
404 | #define LUA_NUMBER_SCAN "%lf" | ||
405 | #define LUA_NUMBER_FMT "%.14" LUA_NUMBER_FRMLEN "g" | ||
406 | #define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) | ||
407 | #define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */ | ||
408 | |||
409 | |||
410 | /* | ||
411 | @@ l_mathop allows the addition of an 'l' or 'f' to all math operations | 405 | @@ l_mathop allows the addition of an 'l' or 'f' to all math operations |
412 | */ | 406 | ** |
413 | #define l_mathop(x) x | ||
414 | |||
415 | |||
416 | /* | ||
417 | @@ lua_str2number converts a decimal numeric string to a number. | 407 | @@ lua_str2number converts a decimal numeric string to a number. |
418 | @@ lua_strx2number converts an hexadecimal numeric string to a number. | 408 | @@ lua_strx2number converts an hexadecimal numeric string to a number. |
419 | ** In C99, 'strtod' does both conversions. C89, however, has no function | 409 | ** In C99, 'strtod' does both conversions. C89, however, has no function |
@@ -421,15 +411,51 @@ | |||
421 | ** systems, you can leave 'lua_strx2number' undefined and Lua will | 411 | ** systems, you can leave 'lua_strx2number' undefined and Lua will |
422 | ** provide its own implementation. | 412 | ** provide its own implementation. |
423 | */ | 413 | */ |
414 | |||
415 | #if LUA_SMALL_FLOAT /* { */ | ||
416 | |||
417 | #define LUA_NUMBER float | ||
418 | |||
419 | #define LUAI_UACNUMBER double | ||
420 | |||
421 | #define LUA_NUMBER_FRMLEN "" | ||
422 | #define LUA_NUMBER_SCAN "%f" | ||
423 | #define LUA_NUMBER_FMT "%.7g" | ||
424 | |||
425 | #define l_mathop(op) op##f | ||
426 | |||
427 | #define lua_str2number(s,p) strtof((s), (p)) | ||
428 | |||
429 | #else /* }{ */ | ||
430 | |||
431 | #define LUA_NUMBER_DOUBLE | ||
432 | #define LUA_NUMBER double | ||
433 | |||
434 | #define LUAI_UACNUMBER double | ||
435 | |||
436 | #define LUA_NUMBER_FRMLEN "" | ||
437 | #define LUA_NUMBER_SCAN "%lf" | ||
438 | #define LUA_NUMBER_FMT "%.14g" | ||
439 | |||
440 | #define l_mathop(op) op | ||
441 | |||
424 | #define lua_str2number(s,p) strtod((s), (p)) | 442 | #define lua_str2number(s,p) strtod((s), (p)) |
425 | 443 | ||
444 | #endif /* } */ | ||
445 | |||
446 | |||
426 | #if defined(LUA_USE_STRTODHEX) | 447 | #if defined(LUA_USE_STRTODHEX) |
427 | #define lua_strx2number(s,p) strtod((s), (p)) | 448 | #define lua_strx2number(s,p) lua_str2number(s,p) |
428 | #endif | 449 | #endif |
429 | 450 | ||
430 | 451 | ||
452 | #define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n)) | ||
453 | |||
454 | |||
455 | |||
431 | /* | 456 | /* |
432 | @@ The luai_num* macros define the primitive operations over numbers. | 457 | @@ The luai_num* macros define the primitive operations over numbers. |
458 | @* They should work for any size of floating numbers. | ||
433 | */ | 459 | */ |
434 | 460 | ||
435 | /* the following operations need the math library */ | 461 | /* the following operations need the math library */ |
@@ -455,30 +481,35 @@ | |||
455 | 481 | ||
456 | 482 | ||
457 | /* | 483 | /* |
458 | @@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger. | 484 | @@ LUA_INTEGER is the integer type used by Lua. |
459 | ** CHANGE that if ptrdiff_t is not adequate on your machine. (On most | 485 | ** |
460 | ** machines, ptrdiff_t gives a good choice between int or long.) | ||
461 | */ | ||
462 | #define LUA_INTEGER long long | ||
463 | |||
464 | /* | ||
465 | @@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER. | 486 | @@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER. |
466 | */ | 487 | ** |
467 | #define LUA_UNSIGNED unsigned LUA_INTEGER | ||
468 | |||
469 | /* | ||
470 | @@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers. | 488 | @@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers. |
471 | @@ LUA_INTEGER_SCAN is the format for reading integers. | 489 | @@ LUA_INTEGER_SCAN is the format for reading integers. |
472 | @@ LUA_INTEGER_FMT is the format for writing integers. | 490 | @@ LUA_INTEGER_FMT is the format for writing integers. |
473 | @@ lua_integer2str converts an integer to a string. | 491 | @@ lua_integer2str converts an integer to a string. |
474 | @@ LUAI_MAXINTEGER2STR is maximum size of previous conversion. | ||
475 | */ | 492 | */ |
493 | |||
494 | #if LUA_SMALL_INT /* { */ | ||
495 | |||
496 | #define LUA_INTEGER long | ||
497 | |||
498 | #define LUA_INTEGER_FRMLEN "l" | ||
499 | |||
500 | #else /* }{ */ | ||
501 | |||
502 | #define LUA_INTEGER long long | ||
503 | |||
476 | #define LUA_INTEGER_FRMLEN "ll" | 504 | #define LUA_INTEGER_FRMLEN "ll" |
505 | |||
506 | #endif /* } */ | ||
507 | |||
477 | #define LUA_INTEGER_SCAN "%" LUA_INTEGER_FRMLEN "d" | 508 | #define LUA_INTEGER_SCAN "%" LUA_INTEGER_FRMLEN "d" |
478 | #define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d" | 509 | #define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d" |
479 | #define lua_integer2str(s,n) sprintf((s), LUA_INTEGER_FMT, (n)) | 510 | #define lua_integer2str(s,n) sprintf((s), LUA_INTEGER_FMT, (n)) |
480 | #define LUA_MAXINTEGER2STR 32 | ||
481 | 511 | ||
512 | #define LUA_UNSIGNED unsigned LUA_INTEGER | ||
482 | 513 | ||
483 | /* }================================================================== */ | 514 | /* }================================================================== */ |
484 | 515 | ||
@@ -492,38 +523,9 @@ | |||
492 | ** without modifying the main part of the file. | 523 | ** without modifying the main part of the file. |
493 | */ | 524 | */ |
494 | 525 | ||
495 | #define LUA_SMALL_INT | ||
496 | #define LUA_SMALL_FLOAT | ||
497 | |||
498 | |||
499 | #if defined(LUA_SMALL_FLOAT) /* { */ | ||
500 | 526 | ||
501 | #undef LUA_NUMBER_DOUBLE | ||
502 | 527 | ||
503 | #undef LUA_NUMBER | ||
504 | #define LUA_NUMBER float | ||
505 | |||
506 | #undef LUA_NUMBER_SCAN | ||
507 | #define LUA_NUMBER_SCAN "%f" | ||
508 | |||
509 | #undef LUA_NUMBER_FMT | ||
510 | #define LUA_NUMBER_FMT "%.7g" | ||
511 | 528 | ||
512 | #undef l_mathop | ||
513 | #define l_mathop(x) x##f | ||
514 | |||
515 | #endif /* } */ | ||
516 | |||
517 | |||
518 | #if defined (LUA_SMALL_INT) /* { */ | ||
519 | |||
520 | #undef LUA_INTEGER | ||
521 | #define LUA_INTEGER long | ||
522 | |||
523 | #undef LUA_INTEGER_FRMLEN | ||
524 | #define LUA_INTEGER_FRMLEN "l" | ||
525 | |||
526 | #endif /* } */ | ||
527 | 529 | ||
528 | #endif | 530 | #endif |
529 | 531 | ||