Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
132 user(s) are online (128 user(s) are browsing Forums)

Members: 0
Guests: 132

more...

Support us!

Headlines

 
  Register To Post  

int pointers Vs float pointers ...
Quite a regular
Quite a regular


See User information
Hi All,

in fact I'm looking to know if floats under amiga are 32 bits length (like int) or not ..
And to be sure on how I can read/write float on memory using pointers ...

Can someone give some short commented examples ?

Thank you.

Kindest Regards,
Fred

All we have to decide is what to do with the time that is given to us.
Go to top
Re: int pointers Vs float pointers ...
Just can't stay away
Just can't stay away


See User information
@freddix

floats are 32-bit, doubles are 64-bit. You can also use the float32 and float64 types from "SDK:Include/include_h/exec/types.h".

#include <stdio.h>

int main () {
    
printf(float size: %d-bit\ndouble size: %d-bit\n",
        (int)sizeof(float)*8, (int)sizeof(double)*8);
    return 0;
}

Go to top
Re: int pointers Vs float pointers ...
Quite a regular
Quite a regular


See User information
@salass00
it's what I suspected :)
But thank you for the confirmation :)

So I can setup a pointer to an int and use it to put a float32 inside memory ?

Regards,
Fred

All we have to decide is what to do with the time that is given to us.
Go to top
Re: int pointers Vs float pointers ...
Quite a regular
Quite a regular


See User information
@freddix

> So I can setup a pointer to an int and use it to put a float32 inside memory ?

Yes, but I'd recommend an uint32 to be absolutely sure it stays 32-bit in the future.

Software developer for Amiga OS3 and OS4.
Develops for OnyxSoft and the Amiga using E and C and occasionally C++
Go to top
Re: int pointers Vs float pointers ...
Home away from home
Home away from home


See User information
@freddix
It would be MUCH safer to use a Union of an int & a float, then you can be sure it is large enough to hold both.

Author of the PortablE programming language.
Go to top
Re: int pointers Vs float pointers ...
Not too shy to talk
Not too shy to talk


See User information
@freddix

In C programming, float is always 32-bit and double is always 64-bit, regardless of what architecture you're coding on.

You have to be careful with pointers. Since both int and float have the same data size (32 bits) the processor has the same alignment restrictions, which means you can write float data into an int and vice versa (not sure why you want to do that though).

Go to top
Re: int pointers Vs float pointers ...
Just popping in
Just popping in


See User information
@freddix

The question that should have been posed is: what are you trying to achieve / do? And by that I don't mean "setup a pointer to an int and use it to put a float32 inside memory", but why do you need to do that?

Go to top
Re: int pointers Vs float pointers ...
Quite a regular
Quite a regular


See User information
@DaveAE
I allocate a block of memory to store object meshes in float and integer format... Why ?

Simply that a vertex uses :
3 floats ( X, Y, Z )
3 floats for normals ( nX, nY, nZ )
1 DWord = diffuse colour
2 floats ( UV texture coordinates )
That mean 36 bytes for each vertex and it contain floats and dword ( I'll use integer for dword )
That why I need to Read/Write int and float from the same memory block.

All we have to decide is what to do with the time that is given to us.
Go to top
Re: int pointers Vs float pointers ...
Quite a regular
Quite a regular


See User information
@freddix

In that case you should define a structure for each vertex and use the structure pointer to refer to each field:

// define structure
struct Vertex
{
float X, Y, Z;
float nX, nY, nZ;
uint32 DiffColour;
float U, V;
};

// now define a pointer to the vertex.
// initialise the pointer to the vertex you want to change
struct Vertex *vertexPtr = ...;

// enter the data into the chosen vertex
vertexPtr->X = ...;
vertexPtr->Y = ...;
(etc)

// step to next vertex
vertexPtr++;

// save data into next vertex
(etc)

cheers
tony
Go to top
Re: int pointers Vs float pointers ...
Just popping in
Just popping in


See User information
@tonyw

Keep in mind that what Freddix is trying to do is make a DarkBasic clone for AmigaOS 4.x and, as a spin-off of AmosPro for the PC, the blocks of memory are very much like Amos Bank formats. You access the memory in these blocks using versions of the BASIC Peek and Poke commands.

@thread

That being said, I'd still use a union of Int32 and Float32 in case endian correction becomes an issue because the byte-swapping opcodes in the PowerPC instruction set only apply to integers. That means you can only endian-swap a float by loading it into a general-purpose register.

@freddix

Does DarkBasic have an equivalent of the AmosPro "Set Double Precision" command that affects all floats in a program? If so, you might want to make the same union an Int64 (or long long) and a Float64 (or a double) for such cases. That way you could still guarantee that the endian correction would take place properly in the C++ syntax in the backend.

Go to top
Re: int pointers Vs float pointers ...
Quite a regular
Quite a regular


See User information
@TonyW:
I can't use this, it should make the coding more complex than it actually is ... and I want to use simple memory allocation not trying to create structure for each cases ...
Memory block size is defined depending on the amount of vertexes used for the object to create ... Simple AllocMem and a simple SetObjectVertex( int ObjectID, int VertexID, float X, float Y, float Z ) can define a vertex. Normals are under an algorithm and UV and COLOR are defined with SetObjectVertexUV( int ObjectID, int VertexID, float UVU, float UVV )...
Samurai_Crow tell you exactly why I don't use structure in that case.

@Samurai_Crow
Never seen this on DarkBASIC nor DarkBASIC Pro.
but it's maybe something I'll add to my "to do list" in case ;)

Thank you for these answers.

All we have to decide is what to do with the time that is given to us.
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project