3 registered members (Ayumi, AndrewAMD, TedMar),
1,016
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Strange values using float or double for array
#208572
05/28/08 03:32
05/28/08 03:32
|
Joined: May 2008
Posts: 5
Newbie999
OP
Newbie
|
OP
Newbie
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
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
panels can't deal with doubles or floats; they need vars. you probably could typecast it:
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
Newbie999
OP
Newbie
|
OP
Newbie
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
zazang
User
|
User
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..
|
|
|
|