Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Numeric overflow issue
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00588052
Message ID:
00588983
Views:
41
Chris --

Indeed. But, the timing comparison is between a hardcoded value and a generic solution.

If you just need to do it once in a while, to respond to an unanticipated error, the TRANSFORM() works just fine.

Otherwise, you have to create the constant that you're comparing to, by getting info from AFIELDS(), creating a string of 9's to represent whole and decimal values, then do a VAL of that. Certainly, when dealing with a large data set, that would be worthwhile.

Jay

>TRANSFORM is substancially slower.
>
>
>USE myTable
>
>* Test 1 Million TRANSFORMS
>t= SECONDS()
>FOR i = 1 TO 1000000
>	x= '*' $ TRANSFORM(Num)
>ENDFOR
>?SECONDS() - t
>* 5.057 seconds
>
>* Test 1 Million Comparisons
>t= SECONDS()
>FOR i = 1 TO 1000000
>	x= Num > 99999999    && Field Length is 8
>ENDFOR
>?SECONDS() - t
>* 1.322 Seconds
>
>CLOSE DATA
>
>
>almost 4 seconds slower over a million tests.
>put this over a substancial data set and you would be getting quite the performance hit.
>
>
>>>>Chris and Antonio,
>>>>
>>>>Testing for myField = 1/0 returns true on a field with a numeric overflow condition. So this should be a good general solution, or you could SCAN/ENDSCAN and check the condition on each record if necessary:
>>>>
>>>>REPLACE myField with 0 for myField = 1/0
>>>>
>>>>>
>>>>>AFIELDS gives some info, and there are a few more that I cant think of off the top of my head.
>>>>>But by passing the Size and Dec you can use this for more then just a field of an opened database. Making it a general approach.
>>>>>If I was doing something with checking for overflows, I would no doubt do an AFIELDS()
>>>>>then Loop through that, take the size and precision, pass it into the above code, and then replace for myField > maxVal, though it isnt the best way to do the replacement either, replace for locks the entire table if im not mistaken.
>>>>>
>>>
>>>I can not get that condition to be true.
>>>I overflowed a field,
>>>
>>>
>>>?FSize("Num")   => 5
>>>REPLACE Num WITH 99999999999
>>>? Num            => *******
>>>? Num = 1/0      => .F.
>>>
>>
>>Try:
>>
>>
>>? "*" $ TRANSFORM (Num)
>>
>>
>> Jay
Previous
Reply
Map
View

Click here to load this message in the networking platform