Board index » delphi » Checking for a whole number
Jimbah
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT

Jimbah
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Checking for a whole number
hi,
How can I check to find out if something entered is a whole number (i.e. 13) or a fraction (ie13.4)? Ps. ITS SNOWING!! Damons rule, Hill and Albarn, Jordan and BLUR 
Bob Scho
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Checking for a whole numberQuoteJimbahb wrote: variable. If as a string, I would check for the decimal point. If as a real, I would check to see if it is equal to the integer nearest to it (I'm assuming you know the Standard Pascal function that gives you this, right?). Bob Schor 
Jimbah
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Checking for a whole numberQuote
I've been messing about converting the thing and everything. Thanks a lot. John 
Mike Copela
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Checking for a whole numberQuote> > How can I check to find out if something entered is a whole number number could be negative. Or a Val of a Real variable could/would work with a whole number, but there are ways to test or convert it to integer, etc. All sorts of things one _might_ want or need to do, depending on the application's requirements. My point being, the original posted question is pretty vague, and there could easily be more factors than we stated, right? 8<}} 
netn..
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Checking for a whole numberIn article <01be868e$ddf43640$LocalHost@home>, "Jimbahb" <Jimb...@hotmailNOSPAM.com> wrote: Quote> hi, consider 13.0 or 1.3e1 to be "whole" numbers. In that case, given a floatingpoint variable x, the expression (frac(x)=0.0) will return TRUE if x is a "whole" number and FALSE if it is not. . == Posted via Deja News, The Discussion Network == 
pgra..
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Checking for a whole numberQuotenetn...@altavista.net wrote: consider 13.0 or 1.3e1 to be "whole" numbers. In that case, given a floatingpoint variable x, the expression (frac(x)=0.0) will return TRUE if x is a "whole" number and FALSE if it is not. Or, perhaps you should use (abs(frac(x))< 1.2 x 10^4932 Phil == Posted via Deja News, The Discussion Network == 
phadr..
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Checking for a whole numberIn article <tWIR2.1124$4I2.6...@newsfeed.slurp.net>, Quotepgra...@dy{*word*193}.net wrote: 1) 1.2 x 10^4932 is not a valid IEEE 754 number 2) if the number you gave were valid, your expression would 3) frac(x)=0.0 is faster, simpler, and returns TRUE if and only if . == Posted via Deja News, The Discussion Network == 
Osmo Ronkan
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Checking for a whole numberQuoteIn article <7f5483$oi...@nnrp1.dejanews.com>, <netn...@altavista.net> wrote: program we are talking about? Osmo 
pgra..
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Checking for a whole numberQuotephadr...@iname.com wrote: Quote pgra...@dy{*word*193}.net wrote: > Checking for the existence of a decimal point won't work if you want to > consider 13.0 or 1.3e1 to be "whole" numbers. In that case, given a > floatingpoint variable x, the expression (frac(x)=0.0) will return TRUE if > x is a "whole" number and FALSE if it is not. > > Or, perhaps you should use (abs(frac(x))< 1.2 x 10^4932 not. Some days, it just doesn't pay to get out of bed. 1) 1.2 x 10^4932 is not a valid IEEE 754 number Should have said 1.0 x ...... But, of course, what I meant was 2) if the number you gave were valid, your expression would See above 3) frac(x)=0.0 is faster, simpler, and returns TRUE if and only if That depends! is (1/n)n a whole number? If you answer yes, then try the code that follows. If you answer no, Phil var begin . == Posted via Deja News, The Discussion Network == 
netn..
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Checking for a whole numberIn article <Ro1S2.913$R93.11...@newsfeed.slurp.net>, Quotepgra...@dy{*word*193}.net wrote: Quote> But, of course, what I meant was the problem with your suggestion is that you have given no theoretical why 3.5e4932? why pick this arbitrary value? why not 3.36210314311209e4932, the smallest normal number? why not 3.36210314311208e4932, the largest denormal number? why not 1.0e4933 or 1.0e4934 or 1.0e4935 etc? Quote
frac(x)=0.0 returns TRUE if and only if the internal representation of the number contains no fractional part. See the modification to your example program below to illustrate this. Quote> is (1/n)n a whole number? (t/41.0)*41.0 for example does not yield a "whole number" (no fractional part) for IEEE 754 80bit extended floats. Quote
 Hide quoted text   Show quoted text  Quote
what is really happening: var begin . == Posted via Deja News, The Discussion Network == 
pgra..
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Checking for a whole numberQuotenetn...@altavista.net wrote: frac(x)=0.0 returns TRUE if and only if the internal representation of the number contains no fractional part. See the modification to your example program below to illustrate this. > is (1/n)n a whole number? analytically, yes (for n>0). numerically, not always. But the reason it doesn't yield a whole number is because of My cheap desk calculator says the result is 0.9999982 Does that make What is your definition, if not that a whole number has no fractional part? Has no fractional part within the limits of the process! Try this modification to your program and you will see var begin Because this code yields: i= 41 (t1.0)=5.42101086242752E0020 whole number? FALSE This means that (1/41)*41 does not equal 1? Not in my book. Phil 
netn..
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Checking for a whole numberIn article <3MmS2.2397$R93.22...@newsfeed.slurp.net>, Quotepgra...@dy{*word*193}.net wrote: (1/41)*41 _ought_ to be, but rather what (1/41)*41 actually _is_. The fact is, on an Intel machine using extendedprecision 80bit floatingpoint arithmetic, (1/41)*41 is *not* equal to 1, no matter how much you would like it to be so. Introducing an arbitrary fudge factor, without any theoretical foundation, is asking for trouble. It may seem to give the "correct" answer in some finite set of examples you try, but it's likely to fail at some edge condition when you least expect it. Quote
not yield a "whole number" (no fractional part) when you use it to evaluate the expression (1/41)*41. Quote
performed. Assigning a fixed arbitrary limit without any theoretical foundation is, sorry, sloppy programming.  Hide quoted text   Show quoted text  Quote
Try this Phil: x := 6e4932; Is x a whole number? why or why not? How about if we now divide x by 2: x := x/2.0; Is x a whole number now? why or why not? . == Posted via Deja News, The Discussion Network == 
pgra..
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Checking for a whole numberQuotenetn...@altavista.net wrote: I detect a fundamental misunderstanding here. The question is not what (1/41)*41 is 1. This is the fact. No arbitrailyapproximate piece of softwareassisted hardware can  The fact Perhaps this is the root of our disagreement (rather than my Phil 
phadr..
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Checking for a whole numberIn article <LrFS2.3511$R93.35...@newsfeed.slurp.net>, Quotepgra...@dy{*word*193}.net wrote: think about it, you might learn something. the solution you suggested, abs(frac(x))<3.5e4932, will fail miserably . == Posted via Deja News, The Discussion Network == 
pgra..
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Checking for a whole numberQuotephadr...@iname.com wrote: think about it, you might learn something. So educate me! the solution you suggested, abs(frac(x))<3.5e4932, will fail miserably I agree. What I was looking for was a way to say that the number is a whole  try it. then you will see what "netnews" is My theoretical understanding is lacking  I will admit that. That Phil 
3. Real number error checking?
4. Question on converting Numbers for Payroll Check Printing Routine
6. Number of checked items in a TCheckListBox
7. how do I check for number of users
8. Help with cleaning code on subfunction used to check if number is a prime