Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Arbitary Precision in C#

Name: Anonymous 2006-04-08 9:31

I am a noob in programming and I am trying to write up an algorithm for my maths project. One of the problems seems to be the lack of precision.

This is how the algorithm goes.

Given a number x, you take the floor of x say [x] and find x-[x], if x-[x] is non zero, you find the reciprocal of x-[x] and put that to be the "new" x. And then repeat the process until x-[x] is zero (guaranteed if x is rational) where the algorithm terminates. The problem about the lack of precision seems to occur at the reciprocal step. For example if you take x = 4.3, we have diff = x-[x]=0.3 and 1/diff = 10/3 = 3.333333... . The computer seems to eventually terminate this decimal expansion and when taking the floor and then the respective difference I think it plays havoc on the following reciprocal step.

I have asked one of my friends, who had a go at writing the algorithm as well and he was the one who said I would be needing an Arbitary precision library. Could anyone help me?

Name: Anonymous 2006-04-08 9:45

C# does not have a native primitive (decimal runs out of bits sooner or later) for arbitary precision, you'll need a math library that does, or try F#

Name: Anonymous 2006-04-08 10:01

>>2
>you'll need a math library that does

Where can I get one for C#?

Name: Anonymous 2006-04-08 10:58

fucking google it

Name: Anonymous 2006-04-08 12:21

>>4

I did. If you do better than me, then please feel free.

Name: Anonymous 2006-04-08 14:31

Use C++ or C.

Name: Anonymous 2006-04-08 14:37

>>6

Bleh, fuck that, I think I won't bother with the algorithm after all.

Name: Anonymous 2006-04-08 15:28

Is this really that hard? You can easily implement rational numbers as a class with a numerator and a denominator, and have member functions subtract and reciprocal.

Name: Anonymous 2006-04-08 15:42

>>2
F# is the retarded clone of Objective Caml, brought to you by Microsoft :D

>>8 for teh win!

Name: Anonymous 2006-04-08 20:58

C# for what? .NET? There should be methods in System.Math

Name: Anonymous 2006-04-09 3:29

>>10

using visual c# in visual studio

Name: Anonymous 2006-04-09 6:01 (sage)

visual studio is about as good of a substitute for emacs as C# is for C.

Name: Anonymous 2006-04-09 13:12 (sage)

>>12
that makes it awesome! :O

Name: Anonymous 2006-04-09 15:12

>>1
Be a man, use plain C

Name: Anonymous 2006-04-09 21:24

HASKELL

Name: Anonymous 2006-04-10 0:45

>>14
Damn right. That's what I said.

Name: Anonymous 2006-04-11 11:56

>>1
if(x < 0.0000001) x = 0

or just use two variables for numerator and denominator.

Name: Anonymous 2006-04-14 16:27 (sage)

Haskell would kick ze ass here. Arbitrary-precision types as builtins in the language for the win.

Name: Anonymous 2010-09-21 13:18

Google it.

Name: Anonymous 2010-09-21 14:03

>>1
maths
CORRECT SPELLING

Name: Anonymous 2010-12-06 9:21

Back to /b/, ``GNAA Faggot''

Don't change these.
Name: Email:
Entire Thread Thread List