weird output with typeset -F

weird output with typeset -F

am 15.02.2005 19:56:10 von bfay

Does someone know why I have the weird output in the following piece of
code?

typeset -F5 X=123.456
print $X
5#443


Thanks,
Bernard

Re: weird output with typeset -F

am 15.02.2005 20:40:06 von Chris Barts

bfay@deepcosmos.ca wrote:
> Does someone know why I have the weird output in the following piece of
> code?
>
> typeset -F5 X=123.456
> print $X
> 5#443

Which shell are you using? Under zsh 4.0.7, I get:

typeset -F5 X=123.456
print $X
123.45600

Re: weird output with typeset -F

am 15.02.2005 20:59:38 von bfay

I use ksh on AIX.

Re: weird output with typeset -F

am 15.02.2005 22:48:23 von brian_hiles

bfay@deepcosmos.ca wrote:
> Does someone know why I have the weird output in the following piece
of
> code?
> typeset -F5 X=123.456
> print $X
> 5#443

I would have said that ksh on AIX is _apparently_ ksh version 1993
or newer, which is the only distribution kornshell which implements
the -F (floating point) option to the builtin command typeset;
however, the "5" parameter option is parsed in the context of the
-i option, wherein it defines the radix of the display, not the
formatted width of the display, as it should.

I presume you understand that what "5#443" is telling you is
that 443 is base 5 for 123 [base 10].

Although I cannot verify this, in my experience, AIX OS and apps
are inappropriately "munged" as IBM's source license will allow,
as well as exhibiting "hybrid" characteristics between canonical
distribution versions of apps and tools. This is certainly true
of my experiences with the AIX port of sed(1), which was working
just fine until some IBM programmer was told to remove all
identifying information in sed(1) diagnostic output!

As AIX ksh is truncating the result, it is behaving as if IBM had
added in their ksh88 the compatibility option -F as an "alias" to
option -i. The exhibited behavior is how many (but not all) ksh88
ports work: they accept floating point notation, but do implicit
integral truncation.

A BIG :( for AIX!

I would use the below as a workaround. This solution has the merit
of at least being compatible to non-broken versions of ksh93!

# AIX: use base 10 as radix (default)
# UNIX: 10 char width (default)
typeset -F10 X=123.456
print -f %5d $X

But this is not going to help you if you genuinely need to do
floating point operations in ksh93. In that case, your two alternatives
are to either use dc(1)/bc(1), or download a _real_ ksh93 port for AIX
from:

http://www.research.att.com/sw/download/

=Brian

Re: weird output with typeset -F

am 15.02.2005 22:53:00 von Dan Mercer

wrote in message news:1108497578.417493.293240@g14g2000cwa.googlegroups.com.. .
: I use ksh on AIX.
:

Isn't that ksh88? Floating point is a ksh93 feature (which should be
available, at least as dtksh). What is the result of

$ print ${.sh.version}

?

Dan Mercer

Re: weird output with typeset -F

am 16.02.2005 01:16:35 von frank

If you're on Aix 5 use /usr/bin/ksh93.

wrote in message
news:1108493770.479162.72720@l41g2000cwc.googlegroups.com...
> Does someone know why I have the weird output in the following piece of
> code?
>
> typeset -F5 X=123.456
> print $X
> 5#443
>
>
> Thanks,
> Bernard
>

Re: weird output with typeset -F

am 17.02.2005 19:32:25 von bfay

"Frank" wrote in message news:...
> If you're on Aix 5 use /usr/bin/ksh93.
>
> wrote in message
> news:1108493770.479162.72720@l41g2000cwc.googlegroups.com...
> > Does someone know why I have the weird output in the following piece of
> > code?
> >
> > typeset -F5 X=123.456
> > print $X
> > 5#443
> >
> >
> > Thanks,
> > Bernard
> >


Gentlemen,

My version of ksh is 88 and the beast where I need the floating point
is AIX 4.3. Also, on the beast with AIX 5.2, the floating point on
ksh93 works just fine.

The option -f in the command `print -f %d5 $X` does not work.

I don't want to install ksh93 on my 4.3 box therefore I'll try to
swith to perl.

thanks to everyone,

Bernard