Hi,
I am writing an imagej macro. In it I need to round up to the nearest integer e.g. 2.1 -> 3 Normally this can be done with the ceiling function, is there a function like this in imagej macro language?? I've found round and floor, but no ceil. Cheers, Wes. -- This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail. Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd. Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message. Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom |
2011/8/7 Wes Armour <[hidden email]>:
> Hi, > > > > I am writing an imagej macro. In it I need to round up to the nearest integer e.g. 2.1 -> 3 Normally this can be done with the ceiling function, is there a function like this in imagej macro language?? I've found round and floor, but no ceil. So you could add 1 and then call floor ? Albert -- http://albert.rierol.net http://www.ini.uzh.ch/~acardona/ |
Hi,
On Sun, 7 Aug 2011, Albert Cardona wrote: > 2011/8/7 Wes Armour <[hidden email]>: > > > > I am writing an imagej macro. In it I need to round up to the nearest > > integer e.g. 2.1 -> 3 Normally this can be done with the ceiling > > function, is there a function like this in imagej macro language?? > > I've found round and floor, but no ceil. > > So you could add 1 and then call floor ? Or -floor(-x). Ciao, Dscho |
On Sunday 07 Aug 2011, Dscho wrote:
> On Sun, 7 Aug 2011, Albert Cardona wrote: > > 2011/8/7 Wes Armour <[hidden email]>: > > > I am writing an imagej macro. In it I need to round up to the nearest > > > integer e.g. 2.1 -> 3 Normally this can be done with the ceiling > > > function, is there a function like this in imagej macro language?? > > > I've found round and floor, but no ceil. > > > > So you could add 1 and then call floor ? > > Or -floor(-x). Yes, that one might be better. Ceiling as floor(x +1) does not work for x=0; it returns 1 instead of 0. Cheers Gabriel |
Thanks to you all,
I had been trying... int_part = parseInt(d2s(delta_t,0)); if( int_part < delta_t) { int_part++; } So -floor(-x) is far better :) Cheers, Wes. ________________________________________ From: ImageJ Interest Group [[hidden email]] on behalf of Gabriel Landini [[hidden email]] Sent: 07 August 2011 13:56 To: [hidden email] Subject: Re: ceiling function On Sunday 07 Aug 2011, Dscho wrote: > On Sun, 7 Aug 2011, Albert Cardona wrote: > > 2011/8/7 Wes Armour <[hidden email]>: > > > I am writing an imagej macro. In it I need to round up to the nearest > > > integer e.g. 2.1 -> 3 Normally this can be done with the ceiling > > > function, is there a function like this in imagej macro language?? > > > I've found round and floor, but no ceil. > > > > So you could add 1 and then call floor ? > > Or -floor(-x). Yes, that one might be better. Ceiling as floor(x +1) does not work for x=0; it returns 1 instead of 0. Cheers Gabriel -- This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail. Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd. Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message. Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom |
In reply to this post by Gabriel Landini
Why not floor(x)?
As far as I can see there is no difference in the results. Is there a special reason to put -floor(-x)? Kees -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Gabriel Landini Sent: 07 August 2011 13:57 To: [hidden email] Subject: Re: ceiling function On Sunday 07 Aug 2011, Dscho wrote: > On Sun, 7 Aug 2011, Albert Cardona wrote: > > 2011/8/7 Wes Armour <[hidden email]>: > > > I am writing an imagej macro. In it I need to round up to the nearest > > > integer e.g. 2.1 -> 3 Normally this can be done with the ceiling > > > function, is there a function like this in imagej macro language?? > > > I've found round and floor, but no ceil. > > > > So you could add 1 and then call floor ? > > Or -floor(-x). Yes, that one might be better. Ceiling as floor(x +1) does not work for x=0; it returns 1 instead of 0. Cheers Gabriel |
Hi Kees,
On Mon, 8 Aug 2011, Straatman, Kees R. (Dr.) wrote: > Why not floor(x)? > > As far as I can see there is no difference in the results. Is there a > special reason to put -floor(-x)? Try this: print(-floor(-5.5)); print(floor(5.5)); In other words, floor(x) rounds down, while -floor(-x) rounds up. Ciao, Johannes |
In reply to this post by Wes Armour
Hi Johannes,
Indeed. I was using x=5.5; x = -floor(-x); y = floor(x); print(x, y); so how to write the x = -floor(-x) to get it to round up? Kees -----Original Message----- From: Johannes Schindelin [mailto:[hidden email]] Sent: 08 August 2011 09:18 To: Straatman, Kees R. (Dr.) Cc: [hidden email] Subject: Re: ceiling function Hi Kees, On Mon, 8 Aug 2011, Straatman, Kees R. (Dr.) wrote: > Why not floor(x)? > > As far as I can see there is no difference in the results. Is there a > special reason to put -floor(-x)? Try this: print(-floor(-5.5)); print(floor(5.5)); In other words, floor(x) rounds down, while -floor(-x) rounds up. Ciao, Johannes |
In reply to this post by Wes Armour
Hi Kees,
I had a similar issue. The second floor function is being called on the result of the first. Instead, try: a=5.5; x = -floor(-a); y = floor(a); print(x, y); Andrew Bell Department of Infection, Immunity and Inflammation Maurice Shock Medical Sciences Building University of Leicester University Road Leicester LE1 9HN United Kingdom |
In reply to this post by Krs5
Hi Kees,
On Mon, 8 Aug 2011, Straatman, Kees R. (Dr.) wrote: > Indeed. I was using > > x=5.5; Now x is 5.5. > x = -floor(-x); This is where x becomes 6. > y = floor(x); Rounding 6 down yields 6 ;-) Ciao, Johannes |
In reply to this post by AJBell
Hi Andrew and Johannes
Yes, of course. Thanks. I guess it is the Monday morning bug... Kees -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Andrew James Bell Sent: 08 August 2011 09:47 To: [hidden email] Subject: Re: FW: ceiling function Hi Kees, I had a similar issue. The second floor function is being called on the result of the first. Instead, try: a=5.5; x = -floor(-a); y = floor(a); print(x, y); Andrew Bell Department of Infection, Immunity and Inflammation Maurice Shock Medical Sciences Building University of Leicester University Road Leicester LE1 9HN United Kingdom |
Free forum by Nabble | Edit this page |