+ switch (get_mode_sort(mode))
+ {
+ case irms_int_number:
+ if (sc_comp(value, get_mode_max(mode)->value) == 1) {
+ switch (GET_OVERFLOW_MODE()) {
+ case TV_OVERFLOW_SATURATE:
+ return get_mode_max(mode);
+ case TV_OVERFLOW_WRAP:
+ {
+ char *temp = alloca(sc_get_buffer_length());
+ char *diff = alloca(sc_get_buffer_length());
+ sc_sub(get_mode_max(mode)->value, get_mode_min(mode)->value, diff);
+ sc_val_from_ulong(1, temp);
+ sc_add(diff, temp, diff);
+ sc_sub(value, diff, temp);
+ while (sc_comp(temp, get_mode_max(mode)->value) == 1)
+ sc_sub(temp, diff, temp);
+ return get_tarval(temp, length, mode);
+ }
+ case TV_OVERFLOW_BAD:
+ return tarval_bad;
+ default:
+ return get_tarval(value, length, mode);
+ }
+ }
+ if (sc_comp(value, get_mode_min(mode)->value) == -1) {
+ switch (GET_OVERFLOW_MODE()) {
+ case TV_OVERFLOW_SATURATE:
+ return get_mode_min(mode);
+ case TV_OVERFLOW_WRAP:
+ {
+ char *temp = alloca(sc_get_buffer_length());
+ char *diff = alloca(sc_get_buffer_length());
+ sc_sub(get_mode_max(mode)->value, get_mode_min(mode)->value, diff);
+ sc_val_from_ulong(1, temp);
+ sc_add(diff, temp, diff);
+ sc_add(value, diff, temp);
+ while (sc_comp(temp, get_mode_max(mode)->value) == 1)
+ sc_add(temp, diff, temp);
+ return get_tarval(temp, length, mode);
+ }
+ case TV_OVERFLOW_BAD:
+ return tarval_bad;
+ default:
+ return get_tarval(value, length, mode);
+ }
+ }
+ break;