Author Topic: Difference with floating point values  (Read 1112 times)

0 Members and 2 Guests are viewing this topic.

Brian Alvarez

  • Guest
Difference with floating point values
« on: December 13, 2018, 12:58:11 PM »
 Hello, i am storing values to a variable as follows:

Code: [Select]
macro _sm_m_set(vu, of, dt, nv, ln  a, b, c)
    sys a = @vu + of   
    dt  c = nv
    int b = sizeof(c)
    if ln then b = ln
    copy a, @c, b
end macro

Basically i take the address of the UDT with @vu, then i look for the member offset with + of, then i create a variable c of the UDT member data type, in this case DOUBLE, and store the new value nv on it. the lb is, in case the data is a static string, to write no more than the allowed bytes, then i copy the variable c at the address of the UDT member b number of bytes.

 It works but, is there a way to add a little more accuracy?

Charles Pegge

  • Guest
Re: Difference with floating point values
« Reply #1 on: December 14, 2018, 10:54:40 AM »
I'm uclear. Are you storing floats in string form? Would it be preferable to store them in their native binary?

Brian Alvarez

  • Guest
Re: Difference with floating point values
« Reply #2 on: December 14, 2018, 11:39:20 AM »
 They are stored in binary. UDT strings are also stored in binary (no bstr's).

 By the way, all of a sudden they started behaving better. I improved the code like this:

Code: [Select]
macro _sm_m_set(vu, of, dt, nv, ln  a, b, c)
    dt c = nv
    copy @vu + of, @c, ln
end macro

 The floating point elements now display:

Code: [Select]
123.411
121.09

 PowerBASIC is still slightly faster. There is room for improvement. :)