### Author Topic: mod() in SmplMath  (Read 1119 times)

#### HSE

• Member
• Posts: 545
• <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

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.700000165.800000      1.000000              mod =   0.800000165.900000      1.000000              mod =   0.900000166.000000      1.000000              mod =   1.000000  x =   166.000000166.100000      1.000000              mod =   0.100000166.200000      1.000000              mod =   0.200000166.300000      1.000000              mod =   0.300000166.400000      1.000000              mod =   0.400000166.500000      1.000000              mod =   0.500000166.600000      1.000000              mod =   0.600000166.700000      1.000000              mod =   0.700000166.800000      1.000000              mod =   0.800000166.900000      1.000000              mod =   0.900000167.000000      1.000000              mod =   1.000000  x =   167.000000167.100000      1.000000              mod =   0.100000167.200000      1.000000              mod =   0.200000`

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

Thanks. HSE

#### HSE

• Member
• Posts: 545
• <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

Some rounding previous to mod() is nedeed.

Thanks.

#### jj2007

• Member
• Posts: 7666
• Assembler is fun ;-)
##### 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: 1469
• The base type of a type is the type itself
##### 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 modefslv_fnc_rndint macro frndintendmdefault_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: 545
• <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 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: 545
• <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