Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Numeric overflow issue
Message
From
04/12/2001 03:26:43
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00588052
Message ID:
00589102
Views:
33
Hi, Chris,

Here's my second opinion...

>>>I am trying to do a [replace all] for cField = ***** (Numeric overflow) but I get a error cause ***** has no quotes and isn't a number
>>
>>... for cField>val(replicate('9',fsize('cField')))
>>
>>bye
>
>This wont work if the field has decimals, ie N(10,3)
>Have to write a function to determine max value to do it with a replace like that.

I'm wrong when I said you were right.

In fact, this will work irrespective of decimal places. The only occasion in which a field will hold a value greater than val(replicate('9',fsize('cField'))) is when it overflows. And when it overflows it will allways be bigger than any number we can represent in the field, whether it has decimals or not.

>
>Something like this should work.
>
>
>PROCEDURE maxval
>LPARAMETERS size, dec
>LOCAL cNum
>cNum = REPLICATE('9', dec)
>cNum = "." + m.cNum
>cNum = REPLICATE('9', m.Size - (m.dec + 1)) + m.cNum
>RETURN VAL(m.cNum)
>
This will be even simpler
... for cField>1e+308
which could be the foundation of a generic function that can determine if a numeric value is, well, Not a Number, and does not rely on an idiosyncratic behaviour regarding division by 0 (99.9% of programming languages of the world will throw an exception at this, not to mention all calculators...).

bye
----------------------------------
António Tavares Lopes
Previous
Reply
Map
View

Click here to load this message in the networking platform