Recent

Author Topic: Frexp() doesn't work for me  (Read 3285 times)

Ruptor

  • Full Member
  • ***
  • Posts: 191
Frexp() doesn't work for me
« on: October 12, 2015, 02:04:47 am »
I pass Frexp  30800024238.61462 and it returns
mantissa = 0.89639868350392848
exponent = 35
Am I doing something stupid?
Running Win XP Laz 1.4.4 FPC 2.6.4  SVN 49931

Laksen

  • Hero Member
  • *****
  • Posts: 724
    • J-Software
Re: Frexp() doesn't work for me
« Reply #1 on: October 12, 2015, 02:24:15 am »
0.89639868350392848*(1+2^35)=30800024239.511018756

What did you expect instead?

Ruptor

  • Full Member
  • ***
  • Posts: 191
Re: Frexp() doesn't work for me
« Reply #2 on: October 12, 2015, 02:37:40 am »
OK base 2 so how can I get
mantissa= 3.080002423861462
exponent= 10

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1058
Re: Frexp() doesn't work for me
« Reply #3 on: October 12, 2015, 11:03:19 am »

Ruptor

  • Full Member
  • ***
  • Posts: 191
Re: Frexp() doesn't work for me
« Reply #4 on: October 12, 2015, 01:35:27 pm »
Thanks Jonas. I thought of changing the base this morning but I only wanted to know how far a number was over a million so I just did this
Code: Pascal  [Select][+][-]
  1. while root>1000000 do root:=root/10;
Probably not as efficient as changing base but it doesn't need the math unit and suits my purpose.
The main problem for an amateur high level programmer like me is that Frexp doesn't say it is giving base 2 results and I didn't twig it hence my confusion
« Last Edit: October 12, 2015, 01:37:35 pm by Ruptor »

Laksen

  • Hero Member
  • *****
  • Posts: 724
    • J-Software
Re: Frexp() doesn't work for me
« Reply #5 on: October 12, 2015, 04:19:55 pm »
It doesn't give the base 2 logarithm, it gives the IEEE floating point exponent. There's a slight difference.

You would want: Floor(ln(number)/ln(10))

Ruptor

  • Full Member
  • ***
  • Posts: 191
Re: Frexp() doesn't work for me
« Reply #6 on: October 12, 2015, 11:42:31 pm »
OK Thanks Laksen.

 

TinyPortal © 2005-2018