[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug?
From: |
Mike Miller |
Subject: |
Re: Bug? |
Date: |
Tue, 21 Jun 2016 23:11:25 -0700 |
User-agent: |
Mutt/1.6.0 (2016-04-01) |
On Tue, Jun 21, 2016 at 23:20:15 +0200, Marco Atzeri wrote:
>
>
> On 21/06/2016 21:10, Dr.-Ing. Dieter Jurzitza wrote:
> > Dear listmembers,
> > when printing with printf I stumbled across something strange (to me ...):
> >
> > > > A=linspace(0,10,10);
> > > > printf("%d\n", A);
> > 0
> > 1.11111
> > 2.22222
> > 3.33333
> > 4.44444
> > 5.55556
> > 6.66667
> > 7.77778
> > 8.88889
> > 10
> > > >
> >
> > I intentionally forced linspace to create a list of floats.
> >
> > I say strange because I didn't expect this. The format specifier "%d" says
> > an
> > integer is going to be printed. And what is the outcome? floats!
> >
> > Matlab does apparently the same - so, is this (in my understanding erratic
> > ...) behaviour a compatibility - feature?
> >
> > Thank you very much for clarifying,
> > take care
> >
> >
> >
> >
> > Dieter Jurzitza
> >
>
> %d means decimal format not integer
Actually, %d does mean the argument is expected to be an integer.
However, Matlab has the interesting “feature” that if the argument has
more precision than the format specifier, then it is formatted as a
floating point number anyway, overriding whatever you asked for. Octave
4.0 and later should do this correctly, see
http://www.octave.org/NEWS-4.0.html
--
mike
- Bug?, Dr.-Ing. Dieter Jurzitza, 2016/06/21