[Gambas-devel] Problem with MoveScale saved into .form files on gambas2

Benoît Minisini gambas at ...1...
Sun Nov 22 19:20:20 CET 2009


> El día 10 de noviembre de 2009 20:02, Alonso Cárdenas Márquez
> 
> <acardenas at ...598...> escribió:
> > 2009/11/2 Benoît Minisini <gambas at ...1...>:
> >> The Round() function is defined in the subr_math.c source file in the
> >> /main/gbx directory.
> >>
> >> Here is the code, with comments added:
> >>
> >> void SUBR_round(void)
> >> {
> >>  // 'val' is the value of the Round second argument, 0 by default.
> >>
> >>  int val = 0;
> >>  double power;
> >>
> >>  // Starts the subroutine. Actually just initializes a variable named
> >>  // 'NPARAM' with the number of arguments passed to the subroutine, and
> >> a // variable named 'PARAM', that points at the first argument on the //
> >> interpreter stack.
> >>
> >>  SUBR_ENTER();
> >>
> >>  // NPARAM is either 1 or 2 (this is checked by the compiler). If there
> >> is 2 // arguments, extract it from the stack and put it in the 'val'
> >> variable.
> >>
> >>  if (NPARAM == 2)
> >>    val = SUBR_get_integer(&PARAM[1]);
> >>
> >>  // Put 10^'val' inside the power variable. According to your test, the
> >> value // returned by Round() is 1/10th the true value. So the value of
> >> 'power' // should be checked with a debugger.
> >>
> >>  power = pow(10, val);
> >>
> >>  // Converts the first argument of Round() to a floating point value.
> >>
> >>  VALUE_conv(&PARAM[0], T_FLOAT);
> >>
> >>  // Defines the return value
> >>
> >>  RETURN->type = T_FLOAT;
> >>
> >>  // Do not use rint(), it does not do what I need.
> >>
> >>  /*RETURN->_float.value = rint(PARAM->_float.value / power) * power;*/
> >>
> >>  // The floor() function returns the largest integer value less than
> >>  // or equal to its argument. By adding 0.5 first, we are actually
> >> rounded // the value to the nearest integer.
> >>
> >>  // The following keeps the number of digits after the decimal point
> >> defined // by the 'val' variable.
> >>
> >>  RETURN->_float.value = floor(PARAM->_float.value / power + 0.5) *
> >> power;
> >>
> >>  // Exit the subroutine by removing the arguments from the interpreter
> >> stack.
> >>
> >>  SUBR_LEAVE();
> >> }
> >>
> >> If you are able to trace the subr_round() function with a debugger, and
> >> see what really happens, you are welcome!
> >>
> >> Regards,
> >>
> >> --
> >> Benoît Minisini
> >
> > Hi  :)
> >
> > I was doing some tests with Round function. I saw that current
> > subr_round() function is calculating the value correctly. The problem
> > is when you assign the value to
> >
> > RETURN->_float.value = floor(PARAM->_float.value / power + 0.5) * power;
> >
> > For example, If you print the same value assigned to a double variable
> >
> > double temp;
> >
> > temp = floor(PARAM->_float.value / power + 0.5) * power;
> >
> > printf("Value: %f", temp);
> >
> > This will show the right value.
> >
> > In another case, I assigned a value of 492,857 to RETURN->_float.value
> > on SUBR_round function (I assigned the value directly into
> > gbx_subr_math.c file). I compiled gbx2 and I called Round function
> > after and I saw that it is showing me the value of 4,92.
> >
> > Maybe it could give you an idea about where I could search for fix the
> > problem.
> >
> > Greetings
> > ACM
> 
> Any news about that?
> 
> Greetings
> ACM
> 

Not really. But it seems something really weird : RETURN->_float.value is 
already a "double", so how setting something in it can change the value?

What architecture do you use exactly?

-- 
Benoît Minisini




More information about the Devel mailing list