Lumio Posted June 15, 2007 Share Posted June 15, 2007 Hi! I try to calculate a high number: 2^100 so I make it like that: pow(2, 100); My result is 1.26765060023E+30 How can I calculate with that value. Or do I have to replace that by my own. Link to comment https://forums.phpfreaks.com/topic/55731-solved-calculating-high-numbers/ Share on other sites More sharing options...
Wildbug Posted June 15, 2007 Share Posted June 15, 2007 BCMath functions? Link to comment https://forums.phpfreaks.com/topic/55731-solved-calculating-high-numbers/#findComment-275374 Share on other sites More sharing options...
Lumio Posted June 15, 2007 Author Share Posted June 15, 2007 Hey thanks! I'll try that... later But thanks! Link to comment https://forums.phpfreaks.com/topic/55731-solved-calculating-high-numbers/#findComment-275519 Share on other sites More sharing options...
Lumio Posted June 15, 2007 Author Share Posted June 15, 2007 Okay... That's great... but I can't calc roots. For example: bcpow(4, 0.5) -> should get 2 ... but I get 1 Link to comment https://forums.phpfreaks.com/topic/55731-solved-calculating-high-numbers/#findComment-275532 Share on other sites More sharing options...
Wildbug Posted June 16, 2007 Share Posted June 16, 2007 It looks like you can't use decimal numbers for the exponent. There is a bcsqrt() function, though. Link to comment https://forums.phpfreaks.com/topic/55731-solved-calculating-high-numbers/#findComment-275892 Share on other sites More sharing options...
utexas_pjm Posted June 16, 2007 Share Posted June 16, 2007 It makes more sense to use fractions anyway -- as x^(1/k) is the kth root of x. Just create a function like: <?php function root($x, $k) { return( ($x < 0 && $k % 2 > 0 ) ? -1 : 1 ) * pow(abs($x), 1/$k); } ?> Best, Patrick Link to comment https://forums.phpfreaks.com/topic/55731-solved-calculating-high-numbers/#findComment-275896 Share on other sites More sharing options...
Wildbug Posted June 16, 2007 Share Posted June 16, 2007 Eh, (a) I don't think that's arbitrary precision, and (b) 1/x is still evaluated as a non-integer. Maybe there's an identity you can find to circumvent that limitation or a homemade function that will do what you want. Link to comment https://forums.phpfreaks.com/topic/55731-solved-calculating-high-numbers/#findComment-275917 Share on other sites More sharing options...
utexas_pjm Posted June 16, 2007 Share Posted June 16, 2007 Oops, sorry I missed the arbitrary precision requirement. Just FYI -- You can use non integer exponents in the pow() function. Link to comment https://forums.phpfreaks.com/topic/55731-solved-calculating-high-numbers/#findComment-275924 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.