Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

partial fractions

1 view
Skip to first unread message

nonews

unread,
Sep 27, 1999, 3:00:00 AM9/27/99
to
how do i convert a decimal pointed number to partial fractions
i.e 6.5 to 6 1/2

Manfred Knemeyer

unread,
Sep 27, 1999, 3:00:00 AM9/27/99
to

nonews <Ogu...@zzapp.org> wrote in message news:37ef8...@news4.his.com...

> how do i convert a decimal pointed number to partial fractions
> i.e 6.5 to 6 1/2

With difficulties.

Just as some decimal numbers can not be represented
exactly (i.e. 1/3 = 0.333333333333333333 . . .), some
decimal numbers which can be represented exactly do
not have an exact binary (floating-point) representation
(i.e. 0.1).

Your 6.5 does have an exact floating point representation,
but in general this will not be true.


Lord Williams

unread,
Sep 28, 1999, 3:00:00 AM9/28/99
to
Most C/C++ compilers have a system that truncate answers beyond
8 digits and also may represent it in a scientific notation format.
And if your trying to get an answer thats requires a certain
decimal precision - its easy to devise a system in
C or C++ that sets the number digits you want to see.

Its no big deal.....


--
Williams

FIAT JUSTITIA


BOB <mtsu...@hotmail.com> wrote in article
<37f0d1f9....@news.rdc1.on.home.com>...
> Just curious, is there an industry standard on the number of decimal
> places to show in C and C++ representations?
>
> Like, "all numbers, if needed, shall express a minimum of X decimal
> places"?
>
> Reason I ask is because it would seem easier to just follow a standard X
> length rather than worrying about precision of the number.
>
> Obviously there is no way to accurately represent 1/3 in decimal form .
> I even have seen .3333 [continued 100 places] and it alters some answers
> enough to be concern.
>
>
> Anyone?? Advice? suggestions?
>
>
> thanks!


R. Hill

unread,
Sep 28, 1999, 3:00:00 AM9/28/99
to

On Tue, 28 Sep 1999, Lord Williams wrote:

> Most C/C++ compilers have a system that truncate answers beyond
> 8 digits and also may represent it in a scientific notation format.
> And if your trying to get an answer thats requires a certain
> decimal precision - its easy to devise a system in
> C or C++ that sets the number digits you want to see.

Here's another Idea: Symbolic processing.

I don't know the purpose for which you intend to use the
"fractions", but if accuracy is ultra-important, you could whip up a
couple of functions that process fractions in a symbolic form, and only
convert them to decimal format when a decimal form is needed.

1 3 11
--- + --- = ----
2 5 10

OTOH, this might be completely overkill...

Good luck,

Roger


Susan Coombes

unread,
Sep 28, 1999, 3:00:00 AM9/28/99
to
Lord Williams <lord...@teleport.com> wrote in message
news:01bf097c$44ac4b00$5c0d1ad8@rlatiola...

> Most C/C++ compilers have a system that truncate answers beyond
> 8 digits

And you know this because you've used most C and C++ compilers?


James Hu

unread,
Sep 28, 1999, 3:00:00 AM9/28/99
to
On Mon, 27 Sep 1999 11:10:10 -0400, nonews <Ogu...@zzapp.org> wrote:
>how do i convert a decimal pointed number to partial fractions
>i.e 6.5 to 6 1/2

Roughly:

Assuming you are reading in the decimal pointed number in as a
string.

1234.5678

Split string at decimal point to make two strings.

1234 5678

The unreduced fraction is the first number, and the fraction that
results from second number divided by 10 to the (length of the
second string) power.

1234 + 5678/10000

Reduce the second fraction to arrive at your answer.

This is not really a C or C++ question.

--
James C. Hu <j...@cs.wustl.edu> Computer Science Doctoral Candidate
http://www.cs.wustl.edu/~jxh/ Washington University in Saint Louis
>>>>>>>>>>>>> I use *SpamBeGone* <URL:http://www.internz.com/SpamBeGone/>

Lord Williams

unread,
Oct 3, 1999, 3:00:00 AM10/3/99
to
Let me reclarify that -

Most C/C++ compilers treat a value thats beyond
a certain value ( sometimes its 8 digits ), will truncate and convert
it into a decimal point format ( this means scientific notation ).

Susan Coombes <nos...@nosite.com> wrote in article
<7sqtqu$log$1...@news7.svr.pol.co.uk>...

Susan Coombes

unread,
Oct 3, 1999, 3:00:00 AM10/3/99
to

Lord Williams <lord...@teleport.com> wrote in message
news:01bf0d60$7d48ae80$9d0d1ad8@rlatiola...

> Let me reclarify that -
>
> Most C/C++ compilers treat a value thats beyond
> a certain value ( sometimes its 8 digits ), will truncate and convert
> it into a decimal point format ( this means scientific notation ).

What do the other compilers do?

R. Hill

unread,
Oct 3, 1999, 3:00:00 AM10/3/99
to Susan Coombes

On Sun, 3 Oct 1999, Susan Coombes wrote:
>
> Lord Williams <lord...@teleport.com> wrote in message
> news:01bf0d60$7d48ae80$9d0d1ad8@rlatiola...

> > Most C/C++ compilers treat a value thats beyond
> > a certain value ( sometimes its 8 digits ), will truncate and convert
> > it into a decimal point format ( this means scientific notation ).
>
> What do the other compilers do?

The way floating point numbers are stored is in 2 parts, (typical) an 8
bit "Whole" number, and a 24 bit mantissima. (I think I spelled that
right, but no book handy.) You can think of this as a computer's version
of scientific notation, something like the form you might have seen
before:

2.3 x 10^9

Several things to note, I think most mantissimas are actuall 23 digits,
with one digit being the sign (+ or -). Also, while standard scientific
notation is in a base 10 exponent, this will be base 2, since computers
use binary numbers.

I Imagine that the reply to your question was "most", because Its possible
to use any combination of "base" and "exponent" that dosen't excede the
size of your variable. The bigger (more bits) the base has, the more
accurate the number is for representing a floating point value, the
bigger the mantissima is, the larger the range of numbers you can store
is. C/C++ uses the 8/23/1 format I described above.

Now, here's a question that is the logical next step: A while back, I was
working on algorithims to factor really large numbers, and I was trying to
figure out if you could change the "base"/mantissima ratio under C/C++. Is
it possible?

(My educated guess, after doing some research, is NO. I don't think ANSI
C/C++ can do this. You could probably write some sort of ASM code that
handled odd variables like that, but not standard C. But, you'd have to
get one of the REAL guru's in the group to confirm this, as I am a meek
guru-in-training.) ;-)

Hope that answers the question.

Roger


Jerry Coffin

unread,
Oct 3, 1999, 3:00:00 AM10/3/99
to
In article <01bf0d60$7d48ae80$9d0d1ad8@rlatiola>,
lord...@teleport.com says...

> Let me reclarify that -
>
> Most C/C++ compilers treat a value thats beyond
> a certain value ( sometimes its 8 digits ), will truncate and convert
> it into a decimal point format ( this means scientific notation ).

I think this is still putting things in a fashion that's at least
confusing and possibly wrong.

With a float, you're guaranteed roughly 6 significant digits in
computations. With a double, you're guaranteed roughly 10 significant
digits. Both these are minimum values of course: it's perfectly legal
(and quite common) for a particular compiler to exceed them,
particularly when you use doubles.

Now, there's a second aspect to things as well: once you've completed
some computation, when/if you print out the result, you have some
degree of precision with which you display the result. For example,
if you're using C and print something out with printf, you might have
something like this:

double x;

// some sort of computation will be done here...

printf("The answer is: %f\n", x);

Now, even though the computation will be done with a minimum precision
of 10 significant digits, you're printing out the result with a
default precision. When you use printf, a simple "%f" rounds the
output to 6 digits even though in this case we're printing out a
double that has at least 10 digits of precision.

You can't usually talk about a single value for the number of digits
and have it make much sense. At the very least, you've got one number
of digits for internal computations, and a possibly different number
of digits when you display things. In addition, you typically have at
least two different sizes of floating point variables, each with its
own precision when you do the calculations. There's a third floating
point type (long double) but it may be the same as a double. OTOH, it
may not be; on most compilers under DOS, for example, float is 32
bits, double is 64 bits and long double is 80 bits.

--
Later,
Jerry.

The universe is a figment of its own imagination.

0 new messages