1. Euphoria equivalent to C typecasting
- Posted by Jonas Temple <jtemple at yhti.net> Aug 02, 2004
- 537 views
All, Dumb question time. I'm trying to come up with the Euphoria equivalent of the following code that gets a floating point value from a spot in memory: longBuffer = (long *) (dataBuffer + bufferIndex); sprintf(prtBuffer+bufferCount+columnInfo[colIndex].width-11, "%11ld", *longBuffer); longBuffer is defined as "long * longBuffer;" Any ideas? Thanks, Jonas
2. Re: Euphoria equivalent to C typecasting
- Posted by Jonas Temple <jtemple at yhti.net> Aug 02, 2004
- 532 views
Jonas Temple wrote: > > All, > > Dumb question time. I'm trying to come up with the Euphoria equivalent > of the following code that gets a floating point value from a spot > in memory: > > longBuffer = (long *) (dataBuffer + bufferIndex); > sprintf(prtBuffer+bufferCount+columnInfo[colIndex].width-11, > "%11ld", *longBuffer); > > longBuffer is defined as "long * longBuffer;" > > Any ideas? > > Thanks, > > Jonas > I apologize, I copied the wrong section. What I'm really interested in is in extracting the floating point value from the memory location: floatBuffer = (float *) (dataBuffer + bufferIndex); sprintf(prtBuffer+bufferCount+columnInfo[colIndex].width-16, "%.8E", *floatBuffer); Thanks, Jonas
3. Re: Euphoria equivalent to C typecasting
- Posted by Matt Lewis <matthewwalkerlewis at yahoo.com> Aug 02, 2004
- 536 views
Jonas Temple wrote: > > > > I apologize, I copied the wrong section. What I'm really interested in > is in extracting the floating point value from the memory location: > > floatBuffer = (float *) (dataBuffer + bufferIndex); > sprintf(prtBuffer+bufferCount+columnInfo[colIndex].width-16, > "%.8E", *floatBuffer); > This is just a 32-bit floating point number, so you could convert using:
float = float32_to_atom( peek( { dataBuffer + bufferIndex, 4})) -- C writes the output of sprintf to a buffer, but -- we just stick it in a sequence in Euphoria: text = sprintf( "%0.8e", float )
Matt Lewis
4. Re: Euphoria equivalent to C typecasting
- Posted by Jonas Temple <jtemple at yhti.net> Aug 02, 2004
- 537 views
Matt Lewis wrote: > > This is just a 32-bit floating point number, so you could convert using: > > <font color="#330033"></font> > <font color="#330033">float = float32_to_atom( </font><font > color="#FF00FF">peek</font><font color="#993333">( </font><font color="#0000FF">{ > </font><font color="#330033">dataBuffer + bufferIndex, 4</font><font > color="#0000FF">}</font><font color="#993333">)</font><font > color="#330033">)</font> > <font color="#FF0055">-- C writes the output of sprintf to a buffer, > but</font> > <font color="#FF0055">-- we just stick it in a sequence in Euphoria:</font> > <font color="#330033">text = </font><font color="#FF00FF">sprintf</font><font > color="#330033">( </font><font color="#00A033">"%0.8e"</font><font > color="#330033">, float )</font> > <font color="#330033"></font> > > Matt Lewis > Thanks Matt! That did the trick. Jonas