Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    907
    Thanks
    301
    Thanked 2 Times in 2 Posts

    Question Data types in PHP

    Hi

    I was going through the official doc of php for data types http://php.net/manual/en/language.types.php

    It seems php does not support long data type. So is double the only datatype in php that supports the highest rage of value?


    Thanks

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,215
    Thanks
    12
    Thanked 338 Times in 334 Posts
    long is an Integer format and double is a Float format, I find that hard to compare. anyways, the manual also states that exact implementation of floats/integers depends on the system used.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • Users who have thanked Dormilich for this post:

    phantom007 (07-15-2013)

  • #3
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    907
    Thanks
    301
    Thanked 2 Times in 2 Posts
    Means if I cast (double) to a numeric variable and if the system does not support it, will it convert the value to negative ?

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,215
    Thanks
    12
    Thanked 338 Times in 334 Posts
    you can’t cast values arbitrarily around, there are only certain castings possible, see http://www.php.net/manual/en/languag...es.typecasting
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    This is mostly to do with the build too. On a x64 compiled PHP, your integer is 64-bit in length. Although even with an x64 build, you can never deal with signed numbers (much like java), although you can always work with packed binary and interpreted it as unsigned when you see fit.

    You can still of course work with larger numbers. Mathematically you can use the GMP or BCMath for larger numbers. Otherwise, yep you're stuck using the less accurate double. Languages like php would actually greatly benefit from the use of operator overloads; it's a pity that they don't have them. If it did, you could simply chain together the + to work with bcmath directly which would be super.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,903
    Thanks
    15
    Thanked 226 Times in 226 Posts
    BC is a Unix program, available on just about any 'nix system. The php version of BC Math is a sort of pale imitation of the original, which you can install and run, by using php, on any 'nix, but you need shell access. BC means basic calculator, but it's much more than that, and it runs very fast. I made a little php page on my localhost home system, which can run BC.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •