formatting math output

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

formatting math output

KP Kirchdörfer
Hi;

being a casual progammer and since NetRexx targets to be easy to use a
dumb question for professionals.

How to do a math easyily for file size.

>>> "lrptemp/zebra.lrp"
>v> myfile "lrptemp/zebra.lrp"
141 *=* mysize=long myfile.length()
>v> mysize "161145"

Question is how to get size in kb instead of bytes?

TIA kp

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: formatting math output

Robert L Hamilton
Add mysize = mysize/1000
 
Bob Hamilton

On Wed, Jul 11, 2012 at 12:19 PM, KP Kirchdörfer <[hidden email]> wrote:
Hi;

being a casual progammer and since NetRexx targets to be easy to use a
dumb question for professionals.

How to do a math easyily for file size.

>>> "lrptemp/zebra.lrp"
>v> myfile "lrptemp/zebra.lrp"
141 *=* mysize=long myfile.length()
>v> mysize "161145"

Question is how to get size in kb instead of bytes?

TIA kp

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: formatting math output

KP Kirchdörfer
sorry, I'd liked to respond to list instead of private email...

kp


Am 11.07.2012 19:41, schrieb Robert Hamilton:
> > Add mysize = mysize/1000
> >
> > Bob Hamilton

Thx - thats "only" nearby

141 *=* mysize=long myfile.length()
     >v> mysize "161145"
 142 *=* kb=mysize/1000
     >v> kb "161.145"

But: ls -alh zebra.lrp  162K

So how to format size to kb?

kp


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: formatting math output

Jeff Hennick
 From info ls :
> `-h'
> `--human-readable'
>       Append a size letter such as `M' for megabytes to each size.
>       Powers of 1024 are used, not 1000; `M' stands for 1,048,576 bytes.
>       Use the `--si' option if you prefer powers of 1000.
So, divide 1024 and round up to whole for KB.  If you want to be fuller,
first check that it is larger than 1023B.  Check again to see if you
have to goto MB by again dividing by 1024, etc. to GB and beyond.

On 7/11/2012 2:07 PM, KP Kirchdörfer wrote:

> sorry, I'd liked to respond to list instead of private email...
>
> kp
>
>
> Am 11.07.2012 19:41, schrieb Robert Hamilton:
>>> Add mysize = mysize/1000
>>>
>>> Bob Hamilton
> Thx - thats "only" nearby
>
> 141 *=* mysize=long myfile.length()
>       >v> mysize "161145"
>   142 *=* kb=mysize/1000
>       >v> kb "161.145"
>
> But: ls -alh zebra.lrp  162K
>
> So how to format size to kb?
>
> kp
>
>
> _______________________________________________
> Ibm-netrexx mailing list
> [hidden email]
> Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
>
>


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: formatting math output

alansam
Am 11.07.2012 19:41, schrieb Robert Hamilton:
Add mysize = mysize/1000

Bob Hamilton
Thx - thats "only" nearby

141 *=* mysize=long myfile.length()
      >v> mysize "161145"
  142 *=* kb=mysize/1000
      >v> kb "161.145"

But: ls -alh zebra.lrp  162K

So how to format size to kb?

The length() function appears to be returning a long so you probably need to coerce it back into a Rexx object then you'll need to do some rounding and formatting or use a ceiling function.  Here are some examples:

mysize = long 161145

m = ''
m[1, 1] = Rexx(mysize)
m[1, 2] = (mysize / 1000).format(null, 3) -- to 3 decimal places
m[1, 3] = (mysize / 1000).format(null, 0) -- rounded
m[1, 4] = (mysize / 1000 + 0.5).format(null, 0) -- rounded up to nearest integer
m[1, 5] = Math.ceil(mysize / 1000.0) -- ceiling
m[2, 1] = Rexx(mysize)
m[2, 2] = (mysize / 1024).format(null, 3)
m[2, 3] = (mysize / 1024).format(null, 0)
m[2, 4] = (mysize / 1024 + 0.5).format(null, 0)
m[2, 5] = Math.ceil(mysize / 1024.0) -- ceiling

loop i_ = 1 to 2
  say m[i_, 1] 'Bytes ==' m[i_, 2] 'kB ==' m[i_, 3] 'kB [rounded] ==' m[i_, 4] 'kB [next > integer] ==' m[i_, 5] 'kB [ceiling]'
  end i_

this yields:

161145 Bytes == 161.145 kB == 161 kB [rounded] == 162 kB [next > integer] == 162 kB [ceiling]
161145 Bytes == 157.368 kB == 157 kB [rounded] == 158 kB [next > integer] == 158 kB [ceiling]
 
As for kB being bytes / 1000 or bytes / 1024; it probably depends upon the implementor of the file system and tools.

Good luck,
Alan.

--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Alan

--
Needs more cowbell.
Reply | Threaded
Open this post in threaded view
|

Re: formatting math output

Dave Woodman
In reply to this post by KP Kirchdörfer
If you need to round up to the next integer, try

        if kb.trunc <> kb then kb = kb.trunc + 1

Which will round up if there is a decimal component, else leave alone.

If you want to do a "traditional" rounding to the nearest integer, try

        kb.format(null,0)

Cheers,

     Dave.


-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of KP Kirchdörfer
Sent: 11 July 2012 19:07
Cc: IBM Netrexx
Subject: Re: [Ibm-netrexx] formatting math output

sorry, I'd liked to respond to list instead of private email...

kp


Am 11.07.2012 19:41, schrieb Robert Hamilton:
> > Add mysize = mysize/1000
> >
> > Bob Hamilton

Thx - thats "only" nearby

141 *=* mysize=long myfile.length()
     >v> mysize "161145"
 142 *=* kb=mysize/1000
     >v> kb "161.145"

But: ls -alh zebra.lrp  162K

So how to format size to kb?

kp


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: formatting math output

ThSITC
In reply to this post by alansam
May I, *please*, add, for the NetRexx *Users Guide* beloved RexxLA President
Mr. Rene Vincent Jasen is preparing, that ...

the proper usage of the BUILTIN Rexx Function (actually the
*constructor* of class 'Rexx', is totally *improperly*
documented in the currently avalabale docs of Netrexx,

at least as far as I do remember it ...

As far as I do remember, in my limited Brain with only one Ganglion
(Rest is pure Vacuum, as already mentioned <grin>),
I did detect the value of all those available Constructor Variants
only by looking at the generated Java Code ...

... using Netrexx 1.00 (e.g, long time ago :-()

Massa Thomas ;-)
==================================================
 
Am 11.07.2012 21:04, schrieb Alan Sampson:
Am 11.07.2012 19:41, schrieb Robert Hamilton:
Add mysize = mysize/1000

Bob Hamilton
Thx - thats "only" nearby

141 *=* mysize=long myfile.length()
      >v> mysize "161145"
  142 *=* kb=mysize/1000
      >v> kb "161.145"

But: ls -alh zebra.lrp  162K

So how to format size to kb?

The length() function appears to be returning a long so you probably need to coerce it back into a Rexx object then you'll need to do some rounding and formatting or use a ceiling function.  Here are some examples:

mysize = long 161145

m = ''
m[1, 1] = Rexx(mysize)
m[1, 2] = (mysize / 1000).format(null, 3) -- to 3 decimal places
m[1, 3] = (mysize / 1000).format(null, 0) -- rounded
m[1, 4] = (mysize / 1000 + 0.5).format(null, 0) -- rounded up to nearest integer
m[1, 5] = Math.ceil(mysize / 1000.0) -- ceiling
m[2, 1] = Rexx(mysize)
m[2, 2] = (mysize / 1024).format(null, 3)
m[2, 3] = (mysize / 1024).format(null, 0)
m[2, 4] = (mysize / 1024 + 0.5).format(null, 0)
m[2, 5] = Math.ceil(mysize / 1024.0) -- ceiling

loop i_ = 1 to 2
  say m[i_, 1] 'Bytes ==' m[i_, 2] 'kB ==' m[i_, 3] 'kB [rounded] ==' m[i_, 4] 'kB [next > integer] ==' m[i_, 5] 'kB [ceiling]'
  end i_

this yields:

161145 Bytes == 161.145 kB == 161 kB [rounded] == 162 kB [next > integer] == 162 kB [ceiling]
161145 Bytes == 157.368 kB == 157 kB [rounded] == 158 kB [next > integer] == 158 kB [ceiling]
 
As for kB being bytes / 1000 or bytes / 1024; it probably depends upon the implementor of the file system and tools.

Good luck,
Alan.

--
Can't tweet, won't tweet!


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



--
Thomas Schneider (Founder of www.thsitc.com) Member of the Rexx Languge Asscociation (www.rexxla.org) Member of the NetRexx Developer's Team (www.netrexx.org)

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Thomas Schneider, Vienna, Austria (Europe) :-)

www.thsitc.com
www.db-123.com
Reply | Threaded
Open this post in threaded view
|

Re: formatting math output

ThSITC
In reply to this post by Dave Woodman
Time to re-introduce *ceil* and *floor* again as standard functions
(methods) maybe?

As far as I do remember, they are already in package
org.netrexx.thsitc.runtime.compatiblity,
class RexxMath ... (end of advertisment) ;-)

Thomas.
===================================================================
Am 11.07.2012 21:26, schrieb Dave Woodman:

> If you need to round up to the next integer, try
>
> if kb.trunc <> kb then kb = kb.trunc + 1
>
> Which will round up if there is a decimal component, else leave alone.
>
> If you want to do a "traditional" rounding to the nearest integer, try
>
> kb.format(null,0)
>
> Cheers,
>
>       Dave.
>
>
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of KP Kirchdörfer
> Sent: 11 July 2012 19:07
> Cc: IBM Netrexx
> Subject: Re: [Ibm-netrexx] formatting math output
>
> sorry, I'd liked to respond to list instead of private email...
>
> kp
>
>
> Am 11.07.2012 19:41, schrieb Robert Hamilton:
>>> Add mysize = mysize/1000
>>>
>>> Bob Hamilton
> Thx - thats "only" nearby
>
> 141 *=* mysize=long myfile.length()
>       >v> mysize "161145"
>   142 *=* kb=mysize/1000
>       >v> kb "161.145"
>
> But: ls -alh zebra.lrp  162K
>
> So how to format size to kb?
>
> kp
>
>
> _______________________________________________
> Ibm-netrexx mailing list
> [hidden email]
> Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
>
> _______________________________________________
> Ibm-netrexx mailing list
> [hidden email]
> Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
>
>


--
Thomas Schneider (Founder of www.thsitc.com) Member of the Rexx Languge
Asscociation (www.rexxla.org) Member of the NetRexx Developer's Team
(www.netrexx.org)

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Thomas Schneider, Vienna, Austria (Europe) :-)

www.thsitc.com
www.db-123.com
Reply | Threaded
Open this post in threaded view
|

Re: formatting math output

ThSITC
In reply to this post by Robert L Hamilton
Hi Robert, nice answer, BUT: There *is* ***NO ADD Statement in neither Rexx (nor NetRexx) ***

Maybe mixing with COBOL ?

*Or* did I mis-understand something in your reply ?

Thomas.
================================================
Am 11.07.2012 19:41, schrieb Robert Hamilton:
Add mysize = mysize/1000
 
Bob Hamilton

On Wed, Jul 11, 2012 at 12:19 PM, KP Kirchdörfer <[hidden email]> wrote:
Hi;

being a casual progammer and since NetRexx targets to be easy to use a
dumb question for professionals.

How to do a math easyily for file size.

>>> "lrptemp/zebra.lrp"
>v> myfile "lrptemp/zebra.lrp"
141 *=* mysize=long myfile.length()
>v> mysize "161145"

Question is how to get size in kb instead of bytes?

TIA kp

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/




_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



--
Thomas Schneider (Founder of www.thsitc.com) Member of the Rexx Languge Asscociation (www.rexxla.org) Member of the NetRexx Developer's Team (www.netrexx.org)

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Thomas Schneider, Vienna, Austria (Europe) :-)

www.thsitc.com
www.db-123.com
Reply | Threaded
Open this post in threaded view
|

Re: formatting math output

christel.u.w.pachl christel.u.w.pachl
In reply to this post by KP Kirchdörfer
I guess that was an instruction for the human user (programmer) to add a line!?!
Thomas get some slöeep & rest!!!
Walter
---- Thomas Schneider <[hidden email]> schrieb:

> Hi Robert, nice answer, BUT: There *is* ***NO ADD Statement in neither
> Rexx (nor NetRexx) ***
>
> Maybe mixing with COBOL ?
>
> *Or* did I mis-understand something in your reply ?
>
> Thomas.
> ================================================
> Am 11.07.2012 19:41, schrieb Robert Hamilton:
> > Add mysize = mysize/1000
> > Bob Hamilton
> >
> > On Wed, Jul 11, 2012 at 12:19 PM, KP Kirchdörfer
> > <[hidden email] <mailto:[hidden email]>> wrote:
> >
> >     Hi;
> >
> >     being a casual progammer and since NetRexx targets to be easy to use a
> >     dumb question for professionals.
> >
> >     How to do a math easyily for file size.
> >
> >     >>> "lrptemp/zebra.lrp"
> >     >v> myfile "lrptemp/zebra.lrp"
> >     141 *=* mysize=long myfile.length()
> >     >v> mysize "161145"
> >
> >     Question is how to get size in kb instead of bytes?
> >
> >     TIA kp
> >
> >     _______________________________________________
> >     Ibm-netrexx mailing list
> >     [hidden email] <mailto:[hidden email]>
> >     Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
> >
> >
> >
> >
> > _______________________________________________
> > Ibm-netrexx mailing list
> > [hidden email]
> > Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
> >
>
>
> --
> Thomas Schneider (Founder of www.thsitc.com) Member of the Rexx Languge
> Asscociation (www.rexxla.org) Member of the NetRexx Developer's Team
> (www.netrexx.org)

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: formatting math output

KP Kirchdörfer
In reply to this post by alansam
Hi,

many thx to all who responded!

Am 11.07.2012 21:04, schrieb Alan Sampson:

> Am 11.07.2012 19:41, schrieb Robert Hamilton:
>
>>  Add mysize = mysize/1000
>>>>>
>>>>> Bob Hamilton
>>>>>
>>>> Thx - thats "only" nearby
>>>
>>> 141 *=* mysize=long myfile.length()
>>>       >v> mysize "161145"
>>>   142 *=* kb=mysize/1000
>>>       >v> kb "161.145"
>>>
>>> But: ls -alh zebra.lrp  162K
>>>
>>> So how to format size to kb?
>>>
>>
> The length() function appears to be returning a *long* so you probably need
> to coerce it back into a *Rexx* object then you'll need to do some rounding
> and formatting or use a ceiling function.  Here are some examples:
>
> *mysize = long 161145*
> *
> *
> *m = ''*
> *m[1, 1] = Rexx(mysize)*
> *m[1, 2] = (mysize / 1000).format(null, 3) -- to 3 decimal places*
> *m[1, 3] = (mysize / 1000).format(null, 0) -- rounded*
> *m[1, 4] = (mysize / 1000 + 0.5).format(null, 0) -- rounded up to nearest
> integer*
> *m[1, 5] = Math.ceil(mysize / 1000.0) -- ceiling*
> *m[2, 1] = Rexx(mysize)*
> *m[2, 2] = (mysize / 1024).format(null, 3)*
> *m[2, 3] = (mysize / 1024).format(null, 0)*
> *m[2, 4] = (mysize / 1024 + 0.5).format(null, 0)*
> *m[2, 5] = Math.ceil(mysize / 1024.0) -- ceiling*
> *
> *
> *loop i_ = 1 to 2*
> *  say m[i_, 1] 'Bytes ==' m[i_, 2] 'kB ==' m[i_, 3] 'kB [rounded] =='
> m[i_, 4] 'kB [next > integer] ==' m[i_, 5] 'kB [ceiling]'*
> *  end i_*
>
> this yields:
>
> *161145 Bytes == 161.145 kB == 161 kB [rounded] == 162 kB [next > integer]
> == 162 kB [ceiling]*
> *161145 Bytes == 157.368 kB == 157 kB [rounded] == 158 kB [next > integer]
> == 158 kB [ceiling]*
>
> As for kB being bytes / 1000 or bytes / 1024; it probably depends upon the
> implementor of the file system and tools.
>
> Good luck,
> Alan.

What an outstanding explanation! Issue solved.

My mistake has been to search for java classes in the JDK instead of
re-reading the NetRexx documentation carefully. The NetRexx Language has
still some hidden gems for me :), but I should have known better, esp.
having in mind MFC's interest in Math.

kp

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/