Recent

Author Topic: [SOLVED] Java conversion of Double.LongBitsToDouble  (Read 1928 times)

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
[SOLVED] Java conversion of Double.LongBitsToDouble
« on: October 01, 2014, 11:28:13 pm »
Hi, how would you convert this code to pascal?

Type "long" is Int64 (or QWord). "<<" is shl.

But what about Double.LongBitsToDouble?

Code: [Select]
public static double exp(double val) {
 final long tmp = (long) (1512775 * val + 1072632447);
 return Double.longBitsToDouble(tmp << 32);
 }

The code is fast exponential function - approximation of e^x.
« Last Edit: October 02, 2014, 12:36:25 am by Blaazen »
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Java conversion of Double.LongBitsToDouble
« Reply #1 on: October 01, 2014, 11:49:10 pm »
This is my guess:
Code: [Select]
var
 i: int64;
 longBitsToDouble: double absolute i;
..
//return Double.longBitsToDouble(tmp << 32);
 i := tmp << 32;
 Result := longBitsToDouble;

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Java conversion of Double.LongBitsToDouble
« Reply #2 on: October 02, 2014, 12:36:01 am »
Thanks, it works.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

 

TinyPortal © 2005-2018