By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,642 Members | 1,674 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,642 IT Pros & Developers. It's quick & easy.

working with array with floats

P: n/a
I have read a file with the file() command and it contains numbers, numbers
that are larger than 2^32 and now I wonder, will this be a problem if I do
arithemtcis, or is there some easy way to force it to use consider the
array as floatingpoint numbers?
--
I didn't know sci.bio.paleontology was that low traffic until I tried read
the thread "Where is everyone?" and found it to be expired.
Jan 31 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Rik
Gunnar G <de****@comhem.sewrote:
I have read a file with the file() command and it contains numbers,
numbers
that are larger than 2^32 and now I wonder, will this be a problem if I
do
arithemtcis,
I leave that to the people who actually learned the basics, is suspect it
might.
or is there some easy way to force it to use consider the
array as floatingpoint numbers?
You can use floatval() on a string without problems. However, depending on
how the data in that file is stored, you might want to look into the
fscanf() function.
--
Rik Wasmus
Jan 31 '07 #2

P: n/a
On Jan 31, 1:38 pm, Gunnar G <deb...@comhem.sewrote:
I have read a file with the file() command and it contains numbers, numbers
that are larger than 2^32 and now I wonder, will this be a problem if I do
arithemtcis, or is there some easy way to force it to use consider the
array as floatingpoint numbers?
No worries! PHP will automatically convert types for you to hold the
number you want.
>
--
I didn't know sci.bio.paleontology was that low traffic until I tried read
the thread "Where is everyone?" and found it to be expired.

Feb 1 '07 #3

P: n/a
On Wed, 31 Jan 2007 11:38:42 -0800, Gunnar G <de****@comhem.sewrote:
I have read a file with the file() command and it contains numbers,
numbers
that are larger than 2^32 and now I wonder, will this be a problem if I
do
arithemtcis, or is there some easy way to force it to use consider the
array as floatingpoint numbers?

Although PHP's dynamic typing should handle this properly, it might be
useful to convert the string to an unsigned int with sprintf, if you run
into issues:

/* maybe pretend we're looping */
$uintArray[] = sprintf('%u', trim($currentLine)); // this way, huge ints
won't become negative

This is useful when you are converting IPs to longs.

--
Curtis, http://dyersweb.com
Feb 1 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.