Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Ayumi, AndrewAMD, TedMar), 1,016 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Strange values using float or double for array #208572
05/28/08 03:32
05/28/08 03:32
Joined: May 2008
Posts: 5
N
Newbie999 Offline OP
Newbie
Newbie999  Offline OP
Newbie
N

Joined: May 2008
Posts: 5
Another newbie here,

When I declare an array as "var" I can display its contents properly. However, when I declare it as "float" or "double", I get really strange values displayed. I thought using float or double would simply store better precision. Is there more to it than that?

// sample code below displays a strange value of -1056768 instead of -1.


float direction[3] = {0,-1,0};


PANEL* pDisplay =
{
digits (10, 60, "direction[1] = %0.f", *, 1, direction[1]);


flags = VISIBLE;
}

Re: Strange values using float or double for array [Re: Newbie999] #208579
05/28/08 05:13
05/28/08 05:13
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
panels can't deal with doubles or floats; they need vars. you probably could typecast it:
Code:
digits (10, 60, "direction[1] = %0.f", *, 1, (var)direction[1]);


but that's just a guess.

julz


Formerly known as JulzMighty.
I made KarBOOM!
Re: Strange values using float or double for array [Re: Newbie999] #208852
05/30/08 01:12
05/30/08 01:12
Joined: May 2008
Posts: 5
N
Newbie999 Offline OP
Newbie
Newbie999  Offline OP
Newbie
N

Joined: May 2008
Posts: 5
Thanks for explaining about digits. However, there is still something mysterious going on even when I am not displaying the digits.

Running the following code will produce a red dot slightly above the center of the screen. By simply redefining the "myvector" variable from var to double, the dot will be displayed in a different location. By changing it to float, the dot is moved completely off the screen. Why would the location of the dot move by simply changing the precision of the variable??

////////

#include <acknex.h>
#include <default.c>

var myvector[3] = {0,-1,50};

function main()
{
level_load("small.hmp");
while(1)
{
draw_point3d(myvector,vector(0,0,255),100,5);
wait(1);
}

}

Re: Strange values using float or double for array [Re: Newbie999] #208853
05/30/08 02:04
05/30/08 02:04
Joined: Oct 2003
Posts: 702
Z
zazang Offline
User
zazang  Offline
User
Z

Joined: Oct 2003
Posts: 702
maybe u need to typecast myvector to var here too..


I like good 'views' because they have no 'strings' attached..
Re: Strange values using float or double for array [Re: Newbie999] #208911
05/30/08 14:40
05/30/08 14:40
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline
Expert
Excessus  Offline
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
It's the same problem as your first one. When a function expects a var, you must pass it a var. When a function expects a VECTOR* (which is the same as a var[3]), you must pass a VECTOR*.

What happens when you don't is that the bits are interpreted in a way they wheren't intended to when they where written. For example, a var contains bits for the integral parts and bits for the fractional part. A float or double contain bits for the base and exponent.

Re: Strange values using float or double for array [Re: Excessus] #209143
06/01/08 14:07
06/01/08 14:07
Joined: May 2008
Posts: 5
N
Newbie999 Offline OP
Newbie
Newbie999  Offline OP
Newbie
N

Joined: May 2008
Posts: 5
Thanks for explaining all that. It makes sense.

So if VECTOR* is the same as var[3], then I guess I will not be able to get better than 3 decimal place accuracy while doing vector rotations. Or is there another way to get better precision doing vector rotations?

Re: Strange values using float or double for array [Re: Newbie999] #209147
06/01/08 14:29
06/01/08 14:29
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
you could implement your own vector functions.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1