-
Notifications
You must be signed in to change notification settings - Fork 122
Redefining int_t and real_t
Integer is defined as int
, and real is defined as float
by default in MY-BASIC, which fits most situations. Besides it's possible to redefine them with other precision as you need.
There are some data precision related macros in my_basic.h
need to be modified, as follow:
#ifndef int_t
# define int_t int
#endif
#ifndef real_t
# ifdef MB_DOUBLE_FLOAT
# define real_t double
# else /* MB_DOUBLE_FLOAT */
# define real_t float
# endif /* MB_DOUBLE_FLOAT */
#endif /* real_t */
#ifndef mb_strtol
# define mb_strtol(__s, __e, __r) strtol((__s), (__e), (__r))
#endif
#ifndef mb_strtod
# define mb_strtod(__s, __e) strtod((__s), (__e))
#endif
#ifndef MB_INT_FMT
# define MB_INT_FMT "%d"
#endif
#ifndef MB_REAL_FMT
# define MB_REAL_FMT "%g"
#endif
#ifndef MB_FNAN
# ifdef MB_DOUBLE_FLOAT
# define MB_FNAN 0x7ff8000000000000
# else /* MB_DOUBLE_FLOAT */
# define MB_FNAN 0x7fc00000
# endif /* MB_DOUBLE_FLOAT */
#endif /* MB_FNAN */
#ifndef MB_FINF
# ifdef MB_DOUBLE_FLOAT
# define MB_FINF 0x7ff0000000000000
# else /* MB_DOUBLE_FLOAT */
# define MB_FINF 0x7f800000
# endif /* MB_DOUBLE_FLOAT */
#endif /* MB_FINF */
MY-BASIC uses int_t
and real_t
for all internal numeric declarations, therefore changing the definition of them will affect all numeric storage and evaluation. mb_strtol
and mb_strtod
are used to parse numbers. MB_INT_FMT
and MB_REAL_FMT
are used to output int_t
and real_t
in properly ways, you need to redefine them according to specific precision, don't forget to redefine MB_FNAN
and MB_FINF
for NaN
and INF
real values as well.
Added an MB_DOUBLE_FLOAT
macro to simply redefine real_t
as double
precision.
- Principles
- Coding
- Data types
- Standalone shell
- Integration
- Customization
- More scripting API
- FAQ