Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Rounding up in perl

Reply
Thread Tools

Rounding up in perl

 
 
sln@netherlands.com
Guest
Posts: n/a
 
      12-19-2008
On Thu, 18 Dec 2008 23:31:11 -0800, Tim Greer <(E-Mail Removed)> wrote:

>(E-Mail Removed) wrote:
>
>> On Thu, 18 Dec 2008 22:42:35 -0800, Tim Greer <(E-Mail Removed)>
>> wrote:
>>
>>>(E-Mail Removed) wrote:
>>>
>>>> On Thu, 18 Dec 2008 19:52:28 -0800, Tim Greer <(E-Mail Removed)>
>>>> wrote:
>>>>
>>>>>(E-Mail Removed) wrote:
>>>>>
>>>>>
>>>>>>
>>>>>> It says it should not be used for rounding, for TWO reasons.
>>>>>> Thats two references to ROUNDING you say it doesen't use.
>>>>>>
>>>>>> sln
>>>>>
>>>>>Or... it's that it could be used for rounding, but that it's not a
>>>>>good idea, as you could have unexpected results.
>>>> [snip]
>>>> And just what is that?
>>>>
>>>> sln
>>>
>>>It might appear to be working fine and give you the desired/expected
>>>results, but by the nature of it, and as you're warned about in the
>>>docs you quoted yourself, it is not a good idea and probably won't
>>>work
>>>how you expect it to. I don't know what else to say?

>>
>> It is certainty for you, you won't and can't depend on Perl intrinsic
>> functions. Because for you, they work intermittentely and with
>> unexpected results.
>>
>> I wish you luck.
>>
>> sln

>
>I didn't create it, I didn't write the documentation about it. While
>I'm sure one could work with said function to do rounding, it's not
>intended to round and suffers from side effects.

[snip]

Ah, just what is the intention of int()? And what are the 'side' effects?

sln

 
Reply With Quote
 
 
 
 
sln@netherlands.com
Guest
Posts: n/a
 
      12-19-2008
On Thu, 18 Dec 2008 18:52:30 -0600, Tad J McClellan <(E-Mail Removed)> wrote:

>(E-Mail Removed) <(E-Mail Removed)> wrote:
>
>> taking into account that
>> int() does not use the sign in its process of rounding.

>
>
>That is because int() does not *have* a process of rounding.
>
>int() does not do rounding.


This is the last comment I am going to make on this
subject.

The documentation is misleading. This truncating towards 0 is
bull. There is no such thing. Truncating is truncating, period.

It may look like truncating but its not so.

int() rounds DOWN when a positive number and rounds UP when a
negative number. It can't be interpreted in any other fashion.

End of discussion !!


sln

 
Reply With Quote
 
 
 
 
Tim Greer
Guest
Posts: n/a
 
      12-19-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> On Thu, 18 Dec 2008 23:31:11 -0800, Tim Greer <(E-Mail Removed)>
> wrote:
>
>>(E-Mail Removed) wrote:
>>
>>> On Thu, 18 Dec 2008 22:42:35 -0800, Tim Greer <(E-Mail Removed)>
>>> wrote:
>>>
>>>>(E-Mail Removed) wrote:
>>>>
>>>>> On Thu, 18 Dec 2008 19:52:28 -0800, Tim Greer <(E-Mail Removed)>
>>>>> wrote:
>>>>>
>>>>>>(E-Mail Removed) wrote:
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> It says it should not be used for rounding, for TWO reasons.
>>>>>>> Thats two references to ROUNDING you say it doesen't use.
>>>>>>>
>>>>>>> sln
>>>>>>
>>>>>>Or... it's that it could be used for rounding, but that it's not a
>>>>>>good idea, as you could have unexpected results.
>>>>> [snip]
>>>>> And just what is that?
>>>>>
>>>>> sln
>>>>
>>>>It might appear to be working fine and give you the desired/expected
>>>>results, but by the nature of it, and as you're warned about in the
>>>>docs you quoted yourself, it is not a good idea and probably won't
>>>>work
>>>>how you expect it to. I don't know what else to say?
>>>
>>> It is certainty for you, you won't and can't depend on Perl
>>> intrinsic functions. Because for you, they work intermittentely and
>>> with unexpected results.
>>>
>>> I wish you luck.
>>>
>>> sln

>>
>>I didn't create it, I didn't write the documentation about it. While
>>I'm sure one could work with said function to do rounding, it's not
>>intended to round and suffers from side effects.

> [snip]
>
> Ah, just what is the intention of int()? And what are the 'side'
> effects?
>
> sln


Just what it says (Returns the integer portion of EXPR):

int EXPR
int Returns the integer portion of EXPR. If EXPR is omitted,
uses $_. You should not use this function for rounding: one because
it truncates towards 0, and two because machine representations
of floating point numbers can sometimes produce counterintu-
itive results. For example, "int(-6.725/0.025)" produces -268
rather than the correct -269; that’s because it’s really more
like -268.99999999999994315658 instead. Usually, the
"sprintf", "printf", or the "POSIX::floor" and "POSIX::ceil"
functions will serve you better than will int()

I repeat, I didn't say you couldn't use it for rounding, but it's not
the best function for it, unless you are okay with results you probably
don't want now and then (which to me, says it's a bad idea -- which the
docs tell you as well). By all means, if you want to use it for
rounding, go for it (and good luck with that).
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
 
Reply With Quote
 
Ilya Zakharevich
Guest
Posts: n/a
 
      12-19-2008
[A complimentary Cc of this posting was sent to
Tim Greer
<(E-Mail Removed)>], who wrote in article <35I2l.6241$(E-Mail Removed)>:
> I didn't create it, I didn't write the documentation about it.


So do it.

> While I'm sure one could work with said function to do rounding,


int() rounds. Period.

> it's not intended to round


It is.

> and suffers from side effects.


There is no side effects.

[But we had this discussion many times. Perl docs are abyssmal...]

Hope this helps,
Ilya
 
Reply With Quote
 
Tim Greer
Guest
Posts: n/a
 
      12-19-2008
Ilya Zakharevich wrote:

> [A complimentary Cc of this posting was sent to
> Tim Greer
> <(E-Mail Removed)>], who wrote in article
> <35I2l.6241$(E-Mail Removed)>:
>> I didn't create it, I didn't write the documentation about it.

>
> So do it.


Do what? Go back in time and create it or go back in time and write the
documention?

>> While I'm sure one could work with said function to do rounding,

>
> int() rounds. Period.


Just not as well as other methods.

>> it's not intended to round

>
> It is.


Just not accurately in every circumstance (where its own documentation
recommends against using it)

>> and suffers from side effects.

>
> There is no side effects.


According to the documentation it does.

> [But we had this discussion many times. Perl docs are abyssmal...]
>


So rewrite the docs.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
 
Reply With Quote
 
Tim Greer
Guest
Posts: n/a
 
      12-19-2008
Ilya Zakharevich wrote:


<Snip>

PS: I never said int() *won't* round (or can't be used to round). I
even said it could be, but there are better methods.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
 
Reply With Quote
 
Tim Greer
Guest
Posts: n/a
 
      12-19-2008
Ilya Zakharevich wrote:

> [A complimentary Cc of this posting was sent to
> Tim Greer
> <(E-Mail Removed)>], who wrote in article
> <35I2l.6241$(E-Mail Removed)>:
>> I didn't create it, I didn't write the documentation about it.

>
> So do it.
>
>> While I'm sure one could work with said function to do rounding,

>
> int() rounds. Period.
>
>> it's not intended to round

>
> It is.
>
>> and suffers from side effects.

>
> There is no side effects.
>
> [But we had this discussion many times. Perl docs are abyssmal...]
>
> Hope this helps,
> Ilya


Actually, I'm a little surprised that you'd respond like that, so
forgive the additional reply. int() truncates, and just because you can
use it to round, doesn't mean that is its intended purpose. You insist
it's a function intended to round and not truncate? The probelms with
using int to round (in the manner outlined in this thread anyway) are
outlined in the documentation and verified by tests. So, has this
changed from a truncate function to a round function at some point?
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
 
Reply With Quote
 
Ilya Zakharevich
Guest
Posts: n/a
 
      12-20-2008
[A complimentary Cc of this posting was sent to
Tim Greer
<(E-Mail Removed)>], who wrote in article <N3V2l.55503$(E-Mail Removed)>:
> >> I didn't create it, I didn't write the documentation about it.


> > So do it.


> Do what? Go back in time and create it or go back in time and write the
> documention?


Write correct documentation...

> >> While I'm sure one could work with said function to do rounding,

> >
> > int() rounds. Period.


> Just not as well as other methods.


Exactly as well as any other rounding methed.

> >> it's not intended to round


> > It is.


> Just not accurately in every circumstance


int() gives a precise answer. By definition, a precise (and correct
answer can't be "non-accurate".

> (where its own documentation recommends against using it)


Documentation is absolutely wrong.

> >> and suffers from side effects.


> > There is no side effects.


> According to the documentation it does.


Nevertheless.

Hope this helps,
Ilya
 
Reply With Quote
 
Ilya Zakharevich
Guest
Posts: n/a
 
      12-20-2008
[A complimentary Cc of this posting was sent to
Tim Greer
<(E-Mail Removed)>], who wrote in article <hlV2l.55512$(E-Mail Removed)>:
> Actually, I'm a little surprised that you'd respond like that, so
> forgive the additional reply. int() truncates, and just because you can
> use it to round, doesn't mean that is its intended purpose. You insist
> it's a function intended to round and not truncate?


If you want to go back in time, and repeat all these arguments again:

truncation is of 5 different (more or less commonly used) modes of rounding.

Hope this helps,
Ilya
 
Reply With Quote
 
Tim Greer
Guest
Posts: n/a
 
      12-20-2008
Ilya Zakharevich wrote:

> [A complimentary Cc of this posting was sent to


There's no need for the complimentary Cc. I read it here, I don't need
to read it in email as well. Thanks.

> Tim Greer
> <(E-Mail Removed)>], who wrote in article
> <N3V2l.55503$(E-Mail Removed)>:
>> >> I didn't create it, I didn't write the documentation about it.

>
>> > So do it.

>
>> Do what? Go back in time and create it or go back in time and write
>> the documention?

>
> Write correct documentation...


You're welcome to write the correct documentation yourself, since you
disagree with it.

>> >> While I'm sure one could work with said function to do rounding,
>> >
>> > int() rounds. Period.

>
>> Just not as well as other methods.

>
> Exactly as well as any other rounding methed.


Except it doesn't round up as a value to an integer as well as sprintf,
and the fact that truncation isn't "exactly" rounding.

>> >> it's not intended to round

>
>> > It is.

>
>> Just not accurately in every circumstance

>
> int() gives a precise answer. By definition, a precise (and correct
> answer can't be "non-accurate".


See the documentation. If you disagree with it, submit something that's
correct. Argue semantics all you like, it truncates, it doesn't round.
I suppose if you think that's the same effect, I can't help.

>> (where its own documentation recommends against using it)

>
> Documentation is absolutely wrong.


Why not submit something that's correct?

>> >> and suffers from side effects.

>
>> > There is no side effects.

>
>> According to the documentation it does.

>
> Nevertheless.
>


Nevertheless, someone I actually used to respect for their contributions
has resorted to acting like this and aligning their logic with a poster
that doesn't know what the /x modifer if for. Food for thought (not
that I expect it to matter).
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 2.17 What is perl.com? Perl Mongers? pm.org? perl.org? cpan.org? PerlFAQ Server Perl Misc 0 02-03-2011 11:00 AM
FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? PerlFAQ Server Perl Misc 0 01-23-2011 05:00 AM
sprintf rounding with FreeBSD and perl 5.8.x cherbst@gmail.com Perl Misc 5 01-24-2008 10:10 PM
Rounding a float in Perl? jon rogers Perl Misc 18 11-05-2003 08:31 AM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments