Board index » delphi » Ok {$N+} anything for percentages?

Ok {$N+} anything for percentages?

Hello again!

    I'm using Real for percentages. I found a web site last evening that was
talking about using a different data type than Real for %'s. It never said
what he was using for the data type. Was it most likely Real; or is there a
better data type for %s?

    Thanks!

    :) Evan

 

Re:Ok {$N+} anything for percentages?


Quote
In article <8ejq08$...@news.dx.net>, Evan Anderson <e...@pcsnow.com> wrote:
>Hello again!

>    I'm using Real for percentages. I found a web site last evening that was
>talking about using a different data type than Real for %'s. It never said
>what he was using for the data type. Was it most likely Real; or is there a
>better data type for %s?

Could you be more elaborate what you mean. Start by explaining what
kind of a program you are writing. A sample of code might be good.

The problem with reals comes when one adds numbers with fractional
parts, like 0.01 several times. The result will not be exact.

Note that modern CPUs it is better to use the coprocessor types like
double or extended.

You can also redefine real:

{$ifopt n+}
type real=double;
{$endif}

Osmo

Re:Ok {$N+} anything for percentages?


Hello!

    It's just a program where I ask for certain inputs and the user enters
what ever they want, and in the end it's applied to a certain equation.

    Basically I'm still in the planning stage with minimal code written but
where I need the percentages I have them defined as:

                VAR

                    R :real;  {needs to be fraction format}
                    fP :real;  {needs to be fraction format}
                    N :integer;

:) Evan

Quote
"Osmo Ronkanen" <ronka...@cc.helsinki.fi> wrote in message

news:8ek3pa$cal$1@kruuna.Helsinki.FI...
Quote
> In article <8ejq08$...@news.dx.net>, Evan Anderson <e...@pcsnow.com>
wrote:
> >Hello again!

> >    I'm using Real for percentages. I found a web site last evening that
was
> >talking about using a different data type than Real for %'s. It never
said
> >what he was using for the data type. Was it most likely Real; or is there
a
> >better data type for %s?

> Could you be more elaborate what you mean. Start by explaining what
> kind of a program you are writing. A sample of code might be good.

> The problem with reals comes when one adds numbers with fractional
> parts, like 0.01 several times. The result will not be exact.

> Note that modern CPUs it is better to use the coprocessor types like
> double or extended.

> You can also redefine real:

> {$ifopt n+}
> type real=double;
> {$endif}

> Osmo

Re:Ok {$N+} anything for percentages?


Quote
In article <8ek4pn$...@news.dx.net>, Evan Anderson <e...@pcsnow.com> wrote:
>Hello!

>    It's just a program where I ask for certain inputs and the user enters
>what ever they want, and in the end it's applied to a certain equation.

That explains absolutely nothing.

Quote

>    Basically I'm still in the planning stage with minimal code written but
>where I need the percentages I have them defined as:

>                VAR

>                    R :real;  {needs to be fraction format}
>                    fP :real;  {needs to be fraction format}
>                    N :integer;

>:) Evan

Could you try again. Explain what you are writing and how percentages
are relevant to the problem. I cannot read your mind to see what the
problem is. I have to work on basis of what you write here.

Do not use words like "certain" instead explain what what kind.

Osmo

Re:Ok {$N+} anything for percentages?


JRS:  In article <8ek3pa$ca...@kruuna.Helsinki.FI> of Mon, 1 May 2000
17:19:22 seen in news:comp.lang.pascal.borland, Osmo Ronkanen

Quote
<ronka...@cc.helsinki.fi> wrote:
>You can also redefine real:

>{$ifopt n+}
>type real=double;
>{$endif}

Very confusing to any human reader of the code, especially if several
units are used.

IMHO the best thing is to declare variables to be of type Float (so that
the reader knows that he doesn't know exactly what it is), and to define
Float in terms of the standard types.

type float = {$IFOPT N+} extended {$ELSE} real {$ENDIF} ;

For comprehensibility, nothing defined by Borland should be redefined by
the user, except unavoidably.

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 Web <URL: http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
 PAS, EXE in <URL: http://www.merlyn.demon.co.uk/programs/> - see 00index.txt.
 Do not Mail News to me.    Before a reply, quote with ">" or "> " (SoRFC1036)

Other Threads