Hallo Java-forum,
Wie kann man in Java die Mantisse einer double Variablen ohne JNI bzw. loadLibrary ändern?
Code für das Mixqd.DLL:
Wie kann man in Java die Mantisse einer double Variablen ohne JNI bzw. loadLibrary ändern?
Java:
// Erhöhe Mantisse einer double Varibalen um 1
public class Mixqd {
public static native long RetI64(double d);
public static native double RetD64(long l);
public static native long RDTSC();
public static void main(String[] args) {
long l, vorzeichen, exponent, mantisse;
double d=0.025, dneu;
System.loadLibrary("Mixqd");
System.out.println(RetI64(0.025));
System.out.println(RetD64(4582862980812216730L));
System.out.println(RetD64(0x3F9999999999999AL));
l=RetI64(d);
vorzeichen=(l&0x8000000000000000L)>>63;
exponent= (l&0x7FF0000000000000L)>>52;
mantisse= l&0xFFFFFFFFFFFFFL;
System.out.printf("Vorzeichen(1 Bit): %d Exponent(11 Bit): %d Mantisse(52 Bit) %d\n",vorzeichen,exponent,mantisse);
System.out.println(Math.getExponent(d) );
mantisse++;
System.out.println((vorzeichen<<63)+(exponent<<52)+mantisse);
dneu=RetD64((vorzeichen<<63)+(exponent<<52)+mantisse);
System.out.println(dneu);
System.out.printf("epsilon: %e\n",dneu-d);
System.out.println(RDTSC());
System.out.println(RDTSC());
//System.out.println(Math.getMantisse(0.025) );
}
}
/*
4582862980812216730
0.025
0.025
Vorzeichen(1 Bit): 0 Exponent(11 Bit): 1017 Mantisse(52 Bit) 2702159776422298
-6
4582862980812216731
0.025000000000000005
epsilon: 3,469447e-18
1396952647696054
1396952648316758
*/
Code:
; PureBasic 5.71 LTS(x64) Windows
Structure Mixqd : StructureUnion : q.q : d.d : EndStructureUnion : EndStructure
XIncludeFile "d:\_neu\Java\PBJNI_1.0\src\JavaDLL\JNINativeInterface.pb"
; Dank an Sven alias Froggerprogger contact: kurras@schalldesign.de für JNINativeInterface.pb
; https://drive.google.com/uc?export=download&id=0BwDGv21nAMiVSFV0NldDcjhjejg
ProcedureDLL.q Java_Mixqd_RetI64(*env.JNINativeInterface, *obj.Long, d.d)
myMixqd.Mixqd\d=d
ProcedureReturn myMixqd\q
EndProcedure
ProcedureDLL.d Java_Mixqd_RetD64(*env.JNINativeInterface, *obj.Long, q.q)
myMixqd.Mixqd\q=q
ProcedureReturn myMixqd\d
EndProcedure
Structure DoppelLong : longax.l : longdx.l : EndStructure
Structure RDTSCTyp : StructureUnion : longel.DoppelLong : quadel.q : EndStructureUnion : EndStructure
ProcedureDLL.q Java_Mixqd_RDTSC(*env.JNINativeInterface, *obj.Long)
Protected cpuZeit.RDTSCTyp
Protected RegEax.l, RegEdx.l
EnableASM : DisableDebugger
RDTSC
MOV RegEax,eax
MOV RegEdx,edx
cpuZeit\longel\longax=RegEax
cpuZeit\longel\longdx=RegEdx
ProcedureReturn cpuZeit\quadel
EndProcedure