Author Topic: mod function did not work?  (Read 1006 times)

0 Members and 1 Guest are viewing this topic.

chrisc

  • Guest
mod function did not work?
« on: April 26, 2018, 06:29:25 AM »
Hello

i tried using mod function to get mod of a given string length,  but it always return
a whole number ?

 despite using double , float and single to define it

double m8 

 i was calculating the m8 =mod(18,8) which should gives 2.25
but the program below always return  m8 = 2  ?  without the decimal places or mantisa


the code is as below,  maybe i might have done something wrong here? 
any help is appreciated

Code: [Select]
     uses rtl64


uses corewin
def Trim ltrim(rtrim(%1))


double m8 , mantisa

long  LenofSt , whNum , posDot
string givSt , m8st

givSt ="123456789012345678"
LenofSt = Len( Trim(givSt))

 m8 = mod(LenofSt ,8)

'  display the mod and length of given string
  print  " m8 :  "   m8  +  "   Len of string : " LenofSt

' position of dot
  m8st = Trim(str(m8))
  posDot = instr(1,m8st,".")
 

 whNum = Val( left (m8st,posDot-1))

mantisa = m8*8 - whNum

print str(m8) + "    " + whNum + "    " + mantisa



Charles Pegge

  • Guest
Re: mod function did not work?
« Reply #1 on: April 26, 2018, 07:16:31 AM »
Hi Chris,

mod(..) returns the remainder of a division, so for mod(18,8), 2 is the correct result.

mod(18.25,8) would give you a result of 2.25

chrisc

  • Guest
Re: mod function did not work?
« Reply #2 on: April 26, 2018, 07:32:35 AM »
Thanxx Charles

need go back to school