Page 1 of 1

<climits> Equivalent?

Posted: Thu Jun 25, 2015 6:03 pm
by hwbehrens
I recently had the need for both INT_MAX and INT_MIN in Livecode - what solutions are you guys using to accomplish this behavior?

I need to be able to reliably run mathematical operations (min, max, comparators, etc) on pairs of numbers, and when numbers get too large, you start to get very strange behavior. I suppose I could hard-code the values of -999 trillion and 999 trillion, which seem to be a functional limit based on 60 seconds of testing in the message box, but I'd prefer to use a more reliable, version-agnostic method if possible. Any ideas?

(For reference, I'd like to use it to do unified set evaluations in a math library; i.e. tVar < 0 could be thought of as testing whether tVar is in the set (INT_MIN,0), while -5 < tVar <= 0 could be represented as (-5,0] and so on. However, without a reliable way of representing INT_MIN and INT_MAX, single-sided ranges aren't very well-defined sets.)

Re: <climits> Equivalent?

Posted: Wed Jul 01, 2015 11:47 pm
by zaxos
Isn't max() and min() what you want? you can use both of them like max(100min(20)) or something like that :P

Re: <climits> Equivalent?

Posted: Thu Jul 02, 2015 7:32 am
by SparkOut
I think Hans is already familiar with max() and min() but instead trying to determine the computational limit of an integer representation. ie if tVar > 0 then we know it is greater than zero, but we also know that, unlike the implication of the comparison, it is also less than another, unknown, value beyond which a calculation involving tVar would return inconsistent results. I think. Is your question asking for that unknown value Hans?

Re: <climits> Equivalent?

Posted: Mon Dec 19, 2016 5:19 pm
by MaxV
hwbehrens wrote:I recently had the need for both INT_MAX and INT_MIN in Livecode - what solutions are you guys using to accomplish this behavior?

I need to be able to reliably run mathematical operations (min, max, comparators, etc) on pairs of numbers, and when numbers get too large, you start to get very strange behavior. I suppose I could hard-code the values of -999 trillion and 999 trillion, which seem to be a functional limit based on 60 seconds of testing in the message box, but I'd prefer to use a more reliable, version-agnostic method if possible. Any ideas?

(For reference, I'd like to use it to do unified set evaluations in a math library; i.e. tVar < 0 could be thought of as testing whether tVar is in the set (INT_MIN,0), while -5 < tVar <= 0 could be represented as (-5,0] and so on. However, without a reliable way of representing INT_MIN and INT_MAX, single-sided ranges aren't very well-defined sets.)
What do you intend for 999 trillion? 10^13 or 10^19 ??
Because the max reliable direct mathematical operation on number with 64bit computer is around 10^19, over 10^19 you have to create special functions.
I made this job once upon a time, in order to work with number long any size.