Click here to get back home

Reg- Floating point variables

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Reg- Floating point variables Nithy 11-12-2007
Get Chitika Premium
Posted by Nithy on November 12, 2007, 9:13 am
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Posted by smallpond on November 12, 2007, 9:58 am
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Posted by Nithy on November 13, 2007, 12:20 am
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Posted by Jürgen Exner on November 12, 2007, 10:23 am
Please log in for more thread options
Nithy wrote:
> If I run this code, it doesn't terminate when $count reach 0.9. Its
> keep on increasing. And after 5.9 its showing 5.99999999999999 & so
> on..
> But If I limits it within 0.8(if $count = 0.1 - 0.7), it gives the
> proper output. Why is it so?

You must have missed "Basics of Computer Numerics":
Thou shalt not test for equal on floating point numbers

'perldoc -q 999' gives a very brief introduction of why using floating point
numbers has it quirks in Perl, too, just like in any other standard
programming language.

jue



Posted by Nithy on November 13, 2007, 12:19 am
Please log in for more thread options
> Nithy wrote:
> > If I run this code, it doesn't terminate when $count reach 0.9. Its
> > keep on increasing. And after 5.9 its showing 5.99999999999999 & so
> > on..
> > But If I limits it within 0.8(if $count =3D 0.1 - 0.7), it gives the
> > proper output. Why is it so?
>
> You must have missed "Basics of Computer Numerics":
> Thou shalt not test for equal on floating point numbers
>
> 'perldoc -q 999' gives a very brief introduction of why using floating po=
int
> numbers has it quirks in Perl, too, just like in any other standard
> programming language.
>
> jue
Thanks Jue..


Similar ThreadsPosted
adding floating point January 26, 2007, 9:25 pm
perl floating point problem November 8, 2007, 10:09 am
How can I change a Perl floating-point value to a bit vector? October 28, 2004, 7:29 pm
Can Perl be made to use IEEE floating=-point exception handling? August 22, 2005, 11:53 am
floating bar in the line chart April 21, 2008, 1:13 am
How to print at certain point in perl July 19, 2006, 12:08 pm
At what (if any) point does InsideOut become OO-overkill? December 5, 2006, 2:41 pm
What's the point of these lines of code? May 22, 2007, 9:13 pm
Perl's @INC - am I missing the point? April 17, 2008, 12:02 am
Starting Point for backup script January 28, 2005, 3:16 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap