Author Topic: mod() in SmplMath  (Read 962 times)

HSE

  • Member
  • ****
  • Posts: 521
  • <AMD>< 7-32>
mod() in SmplMath
« on: June 19, 2016, 01:43:19 AM »
Hi qWord!

The rrr postulate become true, and so many macros bring a Ghost to live  :biggrin:

I think is a little less glamorous but ...

In this loop I obtein 166.0 mod 1.0 = 1.0 wich have non sense. (always is 1.0 instead of 0.0)
Code: [Select]
165.700000      1.000000              mod =   0.700000
165.800000      1.000000              mod =   0.800000
165.900000      1.000000              mod =   0.900000
166.000000      1.000000              mod =   1.000000
  x =   166.000000
166.100000      1.000000              mod =   0.100000
166.200000      1.000000              mod =   0.200000
166.300000      1.000000              mod =   0.300000
166.400000      1.000000              mod =   0.400000
166.500000      1.000000              mod =   0.500000
166.600000      1.000000              mod =   0.600000
166.700000      1.000000              mod =   0.700000
166.800000      1.000000              mod =   0.800000
166.900000      1.000000              mod =   0.900000
167.000000      1.000000              mod =   1.000000
  x =   167.000000
167.100000      1.000000              mod =   0.100000
167.200000      1.000000              mod =   0.200000


Surely my error, but key operations depends on this function.

Thanks. HSE

HSE

  • Member
  • ****
  • Posts: 521
  • <AMD>< 7-32>
Re: mod() in SmplMath
« Reply #1 on: June 19, 2016, 04:53:16 AM »
Same results with independ modulus calculation. The problem is not mod().

Logical conclusion: ureal8$ it's alive and it's occulting the true numbers  :shock: :shock: :shock:

Some rounding previous to mod() is nedeed.

Thanks.



jj2007

  • Member
  • *****
  • Posts: 7446
  • Assembler is fun ;-)
    • MasmBasic
Re: mod() in SmplMath
« Reply #2 on: June 19, 2016, 05:39:37 AM »
Even if you go for REAL10, there is a point where rounding errors creep in - you can't avoid it completely.

Unless, of course, your data allow multiplying by a fixed value, e.g. 1000000, to let them become integers.

qWord

  • Member
  • *****
  • Posts: 1450
  • The base type of a type is the type itself
    • SmplMath macros
Re: mod() in SmplMath
« Reply #3 on: June 19, 2016, 05:49:28 AM »
If you need to round to integers, add the following macro declaration somewhere after including math.inc.

Code: [Select]
; round to integer in current rounding mode
fslv_fnc_rndint macro
frndint
endm
default_fnc_dscptr2 <rndint>,nArgs=1,fpu=-1,x64=-1
The function is rndint(x).
MREAL macros - when you need floating point arithmetic while assembling!

HSE

  • Member
  • ****
  • Posts: 521
  • <AMD>< 7-32>
Re: mod() in SmplMath
« Reply #4 on: June 19, 2016, 05:58:32 AM »
For some time (perhaps) the minimum interval will not fall below 0.0001. In the classical problem is 0.002. Only is needed divide the numbers by the interval before to round them.

Sorry the in vivo transmition :biggrin: but now (inside the "get to clever" thing) the mod() SmplMath is not working very well, the alternative perfect:
Code: [Select]
                  fld     temp1
                    fdiv    temp2
                    fRndDn        ; the ObjAsm32 function with setting round to floor
                fmul   temp2
                  fsubr temp1
                fstp  tempr15


Thanks qWord! Exactly in this part readability it's not an issue.

HSE

  • Member
  • ****
  • Posts: 521
  • <AMD>< 7-32>
Re: mod() in SmplMath
« Reply #5 on: June 24, 2016, 05:45:04 AM »
I use that sooner than expected!   
Code: [Select]
fSlv4 INTIME = rndint(TIME*1/CINT) {i4}
Thanks  :t