Autoscale large integer calculations to avoid overflow

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chris3020
    New Member
    • May 2022
    • 15

    Autoscale large integer calculations to avoid overflow

    I have some code that will (frequently) generate S sets of C count of relatively large integers N.
    I need the set with the lowest product.

    int S ranges 7 .. 15 (run-time constant defined at startup).
    int C ranges 2 .. 13 (defined by caller for each call).
    int N ranges 0 .. 2000 (values cannot be predicted by caller).
    …any N==0 in a set aborts the generation of that set (S—)
    …if all sets contain N==0, prog (tries to) generate S new sets for the same C
    …if candidates exhausted, prog branches elsewhere.

    I considered iteratively-decreasing bit-shifts, discarding high-product sets at each step, but this is likely to be slow. My programme will repeat this set-selection process many thousands of times: slow is not a happy option.

    Is there a clever (fast) way to "autoscale" this product calculation so I get the best precision possible without overflow?

    Chris (MacM1, Clang, C)
Working...