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 22:09:11 -0500, Uri Guttman <(E-Mail Removed)> wrote:

>>>>>> "s" == sln <(E-Mail Removed)> writes:

>
> s> On Thu, 18 Dec 2008 18:52:30 -0600, Tad J McClellan <(E-Mail Removed)> wrote:
>
> >> That is because int() does not *have* a process of rounding.
> >> int() does not do rounding.

>
> s> Not only does int() round, but there is no way it can return
> s> without rounding.
>
>and you determined that from what text in the docs you quote?
>
>
> s> perlfunc.html
> s> ===============================
> s> Numeric functions
>
> s> ..., int, ...
>
> s> int EXPR
>
> s> int
>
> s> Returns the integer portion of EXPR. If EXPR is omitted,
> s> uses $_. You should not use this function for rounding:
> s> one because it truncates towards 0, and two because machine
> s> representations of floating point numbers can sometimes
> s> produce counterintuitive results.
>
>and where does it say int() does rounding? it even says you should NOT
>use it for rounding. truncation (which is what int() does) is not
>rounding in any sense of the term rounding. your saying otherwise will
>not make it so.
>
>uri


It says it should not be used for rounding, for TWO reasons.
Thats two references to ROUNDING you say it doesen't use.

sln

 
Reply With Quote
 
 
 
 
Tim Greer
Guest
Posts: n/a
 
      12-19-2008
http://www.velocityreviews.com/forums/(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. I'm sure there are other
functions to misuse just as easily, if you prefer.
--
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
 
 
 
 
Tad J McClellan
Guest
Posts: n/a
 
      12-19-2008
(E-Mail Removed) <(E-Mail Removed)> wrote:
> 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.

>
> Not only does int() round,



int() does not do rounding.


> because it truncates towards 0,



int() does do truncating.

truncating is not rounding.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
 
Reply With Quote
 
sln@netherlands.com
Guest
Posts: n/a
 
      12-19-2008
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

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

>(E-Mail Removed) <(E-Mail Removed)> wrote:
>> 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.

>>
>> Not only does int() round,

>
>
>int() does not do rounding.
>
>
>> because it truncates towards 0,

>
>
>int() does do truncating.
>
>truncating is not rounding.


You've confused posts here bud. Your clipping
what the docs? Not my words.

Does it truncate? What does it truncate?
How exactly do you truncate? Please tell us all.
While your at it, tell us what is rounding up and
down and how it relates to Perl.

Then tell us what Perl's int() is good for.

Thanks!

sln

 
Reply With Quote
 
sln@netherlands.com
Guest
Posts: n/a
 
      12-19-2008
On Thu, 18 Dec 2008 21:02:34 -0800, Keith Keller <(E-Mail Removed)-francisco.ca.us> wrote:

>On 2008-12-18, (E-Mail Removed) <(E-Mail Removed)> wrote:
>>
>> Here is a Perl ceil/floor equivalent. The first code section
>> seems to correctly implement floor by taking into account that
>> int() does not use the sign in its process of rounding. The
>> second code section with floor, although intuitive is not correct.
>> For a full proof, all the values between 2.0 - 2.9 should be checked.

>
>Good luck with that proof. The set of all numbers x such that
>2.0 <= x <= 2.9 is uncountable.
>
>Actually...why don't you stop posting till you complete the proof.
>
>--keith


As a proof, I'm only instred in what happens int the +-.1 range (-+)
of .5, not the whole universe of decimal places to the right.

sln
 
Reply With Quote
 
sln@netherlands.com
Guest
Posts: n/a
 
      12-19-2008
On Fri, 19 Dec 2008 05:26:20 GMT, (E-Mail Removed) wrote:

>On Thu, 18 Dec 2008 21:02:34 -0800, Keith Keller <(E-Mail Removed)-francisco.ca.us> wrote:
>
>>On 2008-12-18, (E-Mail Removed) <(E-Mail Removed)> wrote:
>>>
>>> Here is a Perl ceil/floor equivalent. The first code section
>>> seems to correctly implement floor by taking into account that
>>> int() does not use the sign in its process of rounding. The
>>> second code section with floor, although intuitive is not correct.
>>> For a full proof, all the values between 2.0 - 2.9 should be checked.

>>
>>Good luck with that proof. The set of all numbers x such that
>>2.0 <= x <= 2.9 is uncountable.
>>
>>Actually...why don't you stop posting till you complete the proof.
>>
>>--keith

>
>As a proof, I'm only instred in what happens int the +-.1 range (-+)
>of .5, not the whole universe of decimal places to the right.
>
>sln


Although, margins should be considered a factot in hyperbolic
design considerations, takr it with a grain of salt, add .000000000\
00000000000000000000000000000000000000000000000000 000001 and see
how it plays out.

You just never know, you could discover the asteroid that perishes the
earth.

sln

 
Reply With Quote
 
Tim Greer
Guest
Posts: n/a
 
      12-19-2008
(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?
--
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
 
sln@netherlands.com
Guest
Posts: n/a
 
      12-19-2008
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

 
Reply With Quote
 
Tim Greer
Guest
Posts: n/a
 
      12-19-2008
(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. For the record, in
many, many years of coding in Perl, I've never had a single program
have unexpected results. This is probably attributed to the fact that
I use the correct, intended functions for what they were designed for,
assuming I don't roll out my own. Probably, ignoring the intent of a
function not being what you think it is, and the docs warning not to
use it for the purpose you want, is why you're so confused? Don't take
that out on me. Obviously, you _can_ use int() to round, but I doubt
it's going to work like you think. You *do* know what truncation is,
right?
--
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