2 registered members (7th_zorro, dr_panther),
724
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Possible bug in Lite-C 7.80 - duplicating 'double's.
#285107
08/17/09 07:36
08/17/09 07:36
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Try this code...
function whatever()
{
double values[6];
values[0] = (double)2.862738448796;
values[1] = (double)-8.642801642417908;
diag_var("p1 = %.9f x ", (double)values[0]); diag_var("%.9f\n", (double)values[1]);
diag_var("p2 = %.9f x ", (double)values[2]); diag_var("%.9f\n", (double)values[3]);
values[2] = (double)2.86270802130925;
values[3] = (double)-8.642629981040955;
diag_var("p1 = %.9f x ", (double)values[0]); diag_var("%.9f\n", (double)values[1]);
diag_var("p2 = %.9f x ", (double)values[2]); diag_var("%.9f\n", (double)values[3]);
}
In stage1, array is created, but not initialised cause everything will get filled manually. In stage 2, values [0] and [1] get set, then 0,1,2,3 are all displayed. Cool. In stage 3, values [2] and [3] get set, then 0,1,2,3 are all displayed again. WTF??. look at the values of [0] and [1]... They now equal the values of [2] and [3]... WHY? Am I doing something dumb? Its not just the diag_var because if I subtract [2] and [3] from [0] and [1] I get EXACTLY zero on both subtractions. Am I pushing the limits of the 'double' type too far? Im wondering cause the diag_var values are a little different to what I set them to. But I put that down to double->var conversion (which is not important at this time). I dont have a sample, but the EXACT same thing happens if I remove the array and use individually declared doubles. Any ideas please? (and sorry if this is no bug)PS: this code ATM lives alone inside the main function with nothing else running, so theres NO chance of anything else interfering. Running on 7.80 commercial
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Possible bug in Lite-C 7.80 - duplicating 'double's.
[Re: jcl]
#285114
08/17/09 08:35
08/17/09 08:35
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
But I thought by specifying the type like so "values[0] = (double)2.862738448796;" over-rode that limitation, and left it with that type's limitations.(in this case double)
Or are ALL 3DGS variable types limited to 3 decimal places? Even floats? (Note: Ive never had to deal with numbers this "precice" in this ot any other language before) So if 3DGS cant handle this precision of number (apparently being returned by a DLL) Any suggestions on work-arounds? Precision data CANNOT be lost...
Thanks and sorry for not being a bug.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Possible bug in Lite-C 7.80 - duplicating 'double's.
[Re: EvilSOB]
#285117
08/17/09 08:56
08/17/09 08:56
|
Joined: Jul 2000
Posts: 27,986 Frankfurt
jcl
Chief Engineer
|
Chief Engineer
Joined: Jul 2000
Posts: 27,986
Frankfurt
|
A workaround for what? Your code is defining doubles, copying floats into them, and printing them as vars. That's exactly what you're getting. Vars have only 3 digits after the decimal, no matter if they were converted from double. Look here: http://manual.3dgamestudio.net/diag_var.htmWhen you want to see the content of a variable, use printf, which accepts double variables. BTW when you write a constant like "2.862738448796", it is a float number with 6 digits precision. lite-C has double variables, but no double constants. A cast operator like (double) can not add more digits to a number.
|
|
|
Re: Possible bug in Lite-C 7.80 - duplicating 'double's.
[Re: jcl]
#285134
08/17/09 11:07
08/17/09 11:07
|
Joined: Jul 2004
Posts: 1,710
MMike
Serious User
|
Serious User
Joined: Jul 2004
Posts: 1,710
|
EvilSOB thanks for your feedback too about this.
printing this doesnot works on my pc..
float am=2.86270802130925; printf("value is %f ",(double)am);
or
double am=2.86270802130925; printf("value is %f ",am); goes with 8 decimals i guess only
or even this..
double am=2.86270802130925; printf("value is %.20f ",am); // Forcing 20 decimals but the output when reach 7 decimals are wrong..
and of course this wont work.. because its just 6 decimals.
float value=2.862738448796; str_for_float(test,value); error(test);
Last edited by MMike; 08/17/09 11:27.
|
|
|
Re: Possible bug in Lite-C 7.80 - duplicating 'double's.
[Re: EvilSOB]
#285137
08/17/09 11:19
08/17/09 11:19
|
Joined: Jul 2004
Posts: 1,710
MMike
Serious User
|
Serious User
Joined: Jul 2004
Posts: 1,710
|
But I thought by specifying the type like so "values[0] = (double)2.862738448796;" over-rode that limitation, and left it with that type's limitations.(in this case double)
Or are ALL 3DGS variable types limited to 3 decimal places? Even floats? (Note: Ive never had to deal with numbers this "precice" in this ot any other language before) So if 3DGS cant handle this precision of number (apparently being returned by a DLL) Any suggestions on work-arounds? Precision data CANNOT be lost...
Thanks and sorry for not being a bug. how do you compile that piece of code?? my SED is returning sintax errors of cant convert at values[0]=double... error: CONV:DOUBLE::DOUBLE This for me is a limitation.. not a bug of function... this happened once when on space game.. but not this precise, like GPS are.
Last edited by MMike; 08/17/09 11:29.
|
|
|
Re: Possible bug in Lite-C 7.80 - duplicating 'double's.
[Re: jcl]
#285189
08/17/09 14:33
08/17/09 14:33
|
Joined: Apr 2009
Posts: 33 Germany
Bunsen
Newbie
|
Newbie
Joined: Apr 2009
Posts: 33
Germany
|
EvilSOB and MMike are right. There seems to be no double type precision in Lite-C. From Microsoft MSDN: Microsoft Specific
The double type contains 64 bits: 1 for sign, 11 for the exponent, and 52 for the mantissa. Its range is +/–1.7E308 with at least 15 digits of precision.
END Microsoft Specific
#include <stdio.h>
#inlude <windows.h>
double d = 0.12345678901234;
void main()
{
if (d == 0.12345679)
MessageBox(NULL, "equal", "This is wrong!", MB_OK);
char buf[100];
sprintf(buf, "%1.14f", d);
MessageBox(NULL, buf, "Result", MB_OK);
}
Output: Borland C++Builder: 0.12345678901234 (correct!) Atari Lite-C: "equal" + 0.12345679104328 (wrong! last 6 digits are random)
|
|
|
|