Irrational numbers
Moderator: General Moderators
Irrational numbers
is there a way to store irrational numbers in memory? I mean I don't want it saved as a double or a long, because the number simply gets rounded off eventually. So how does one overcome that?
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
You can store irrational numbers by creating your own class for that, but PHP like most other languages doesn't support that (as i know), because how often do you need them?
I haven't had need for them yet, that would be an answer to why.
superDezign: with 'the number simply gets rounded off eventually' probably he means that numbers saved as floating number are limited to used memory (not sure how many PHP allows for floating numbers) for them and saving for example 10/3 is impossible without rounding them.
I haven't had need for them yet, that would be an answer to why.
superDezign: with 'the number simply gets rounded off eventually' probably he means that numbers saved as floating number are limited to used memory (not sure how many PHP allows for floating numbers) for them and saving for example 10/3 is impossible without rounding them.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Not with integers and floating point. They have finite limits natively. As ~ole mentioned, bcmath is something to look at.superdezign wrote:What do you mean by 'the number simply gets rounded off eventually?' Have you done any testing to that extent? PHP is not strict with typing, so I'd assume that it's generous with memory allocation.
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK