Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Math Question

Status
Not open for further replies.

crewchiefpro6

Programmer
Mar 22, 2005
204
US
Is there a foxpro function that will determine if a number can be divided by 2 and not have a fraction?

I know my high school math teacher is probably rolling over in his grade because I am quite sure I used to know this.


Don Higgins
 
If you really jsut need to know if a number is odd or even, bittest(n,0) will be much faster than mod(n,2) or n%2, as mod(n,2) is of course more general. The result of bittest is of course not the rest/fraction, but a boolean value stating is_odd=T/F.

Bye, Olaf.

 
I was going to warn that the Bittest() will only work with integers but it seems to work with floating point numbers too.

Bittest(12.34, 0) returns .F telling us that 12 is not odd,

Bittest(1.23, 0) returns .T. to say that 1 is odd.

Geoff Franklin
 
was just playing aroud and noticed that, yes:

BITTEST(12.1,0) = .f.
BITTEST(12.2,0) = .f.
BITTEST(12.5,0) = .f.
BITTEST(12.9,0) = .f.

proving that 12 is even.. but

BITTEST(12.9999999999999999,0) = .T.

the system capacities help page (field characteristics) says Digits of precision in numeric computations is 16, which i guess means vfp will round up on the 16th decimal place (put 15 9's after the decimal and the return is .f.). granted, i'm no math wiz, but i would think that the 12 would be included in the number of digits?

eh, food for thought..

-- frank~
 
you might also check BITAND(). Spoiler: yes it has it's problems with floating point numbers too. Perhaps use INT() or CEILING() or FLOOR() beforehand...

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top