Hallo Leute, kann mir einer sagen wie ich von einer dezimalen Zahl eine Single Precision Floating Point Number machen will.. also soweit bin ich gekommen: z,b 100.25 100 wird in Binär umgewandelt -->1100100 0.25 wird in Binär umgewandelt -->010 beide zusammen 1100100.010 so jetzt kommt normlizieren..diesen teil verstehe ich nicht hier der Format von Single Floating Point _______________________________ s | Exponent | Mantisse _______________________________ 31 30 23 22 0 kann mir einer helfen? Gruss Bjk
Deine Frage weicht von der Überschrift ab; Du willst eine Fließkommazahl einlesen: 100.25. Das ist nicht mit einem Satz zu beantworten, wenn Du eine allgemeine Lösung suchst und nicht speziell 401/4 wandeln willst. Am besten suchst Du nach Quellcode der C-Funktion 'scanf', deren Aufgabe u.a. diese Wandlung ist. Bei 'scanf' ist eine 'float-lib' Voraussetzung für diese Wandlung.
Ich habe auch ein Problem mit Fließkommazahl umwandlung (ARM7 + NutOS). Ich habe diese Funktionen : /** * * \brief Convert float value to unsigned int value * * \param floatValue * * \returns integer representation of the float value * */ unsigned int COMToInt(float floatValue) { float* pf = &floatValue; void* pv = (void*) pf; unsigned int uVal = (*((unsigned int*)pv)); return uVal; } /** * * \brief Convert unsigned int value to float * * \param unsignedValue * * \returns float representation of the unsigned int value * */ float COMToFloat(unsigned int u) { unsigned int* pu = &u; float fVal = (*((float*)pu)); return fVal; } Ich denke 'float-lib' ist eine Voraussetzung für diese Wandlung. Aber ich weiss das nicht, wie kann ich das 'float-lib' in ARM7 benutzen. Weiß jemand was da helfen könnte?
Ich habe auch ein Problem mit Fließkommazahl umwandlung (ARM7 + NutOS). Ich habe diese Funktionen : /** * * \brief Convert float value to unsigned int value * * \param floatValue * * \returns integer representation of the float value * */ unsigned int COMToInt(float floatValue) { float* pf = &floatValue; void* pv = (void*) pf; unsigned int uVal = (*((unsigned int*)pv)); return uVal; } /** * * \brief Convert unsigned int value to float * * \param unsignedValue * * \returns float representation of the unsigned int value * */ float COMToFloat(unsigned int u) { unsigned int* pu = &u; float fVal = (*((float*)pu)); return fVal; } Ich denke 'float-lib' ist eine Voraussetzung für diese Wandlung. Aber ich weiss das nicht, wie kann ich das 'float-lib' in ARM7 benutzen. Weiß jemand was da helfen könnte?
@ Lidya (Gast) >Ich habe auch ein Problem mit Fließkommazahl umwandlung (ARM7 + NutOS). >Ich denke 'float-lib' ist eine Voraussetzung für diese Wandlung. Nöö, aber für das Rechnen mit Floatzahlen. Je nach Compiler wird die schon automatisch verwendet oder man muss manuell dazulinken, über eine Compilereinstellung. Aber das eigentliche "Problem" löst der Compiler ganz allein, ohne Funktion.
1 | float my_float; |
2 | int my_int; |
3 | |
4 | my_int = my_float; |
Die Umwandlung macht er automatisch. MFG Falk
Vielleich ich habe falsch erzählen. Ich spreche über Indirection und nicht normalen Convertion. Ich gebe hier ein Beispiel: float a = 99.99; unsigned int b = ToInt(a); // So b= 0x42C7FAE1 ; // Siehe http://www.h-schmidt.net/FloatApplet/IEEE754de.html Später ich kann das genaue Float value kriegen: unsigned int c = ToFloat(b); // Da habe ich c = 99.99 wieder und nicht 100 oder 99. Ich habe diese code in mein PC gesetet. Das funktioniert schon in PC aber nicht in ARM7.
Lidya wrote: > Ich denke 'float-lib' ist eine Voraussetzung für > diese Wandlung. Nein. Ist es nicht. Da wird nichts gewandelt (ausser dem Datentyp). Da wird lediglich umgecastet. Die Binäre Darstellung bleibt aber die gleiche. Was hast du denn konkret für ein Problem? Gibt es eine Fehlermeldung vom Compiler oder ein Laufzeitproblem?
Also, kein Fehlermeldung von Compiler. Das Problem ist, als ich ein floating point value mit das obengennante Funktionen umwandeln, bekomme ich ein unerwartete Ergebniss. Als Beispiel: float a = 99.99; unsigned int b = ToInt(a); // So b= 0x42C7FAE1 aber das Ergebniss ist b = 0x00003BE8 ; Die Funktionen funktioniert als ich sie im PC getestet. Aber, leider nicht in ARM7.
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.