c# - Why does SharpDevelop return me this error: Operator '/' cannot be applied to operands of type 'double' and 'System.Numerics.BigInteger'? -



c# - Why does SharpDevelop return me this error: Operator '/' cannot be applied to operands of type 'double' and 'System.Numerics.BigInteger'? -

i'm total novice. i've created c# programme on sharpdevelop uses biginteger structure.

here is:

using system; using system.numerics; using system.linq; namespace hcc { class programme { public static void main(string[] args) { biginteger[] hcc = new[] { biginteger.parse("2"), biginteger.parse("4"), biginteger.parse("6"), biginteger.parse("12"), biginteger.parse("24"), }; double s; int i; s=0; for(i=0; i<hcc.length; i++) { s=s+1.0/hcc[i]; } console.write(""+s); console.readkey(true); } } }

note: i've set first 5 ones, there 1000 big integers. , have more 70 digits.

the problem sharpdevelop displaying error:

operator '/' cannot applied operands of type 'double' , 'system.numerics.biginteger' (cs0019)

it relative line:

s=s+1.0/hcc[i];

what mean? mean can't perform basic operations addition, multiplication , partition on bigintegers?

and importantly: how can solve problem?

you don't want utilize biginteger @ all. instead, decimal might you're looking for.

something this:

decimal[] hcc = new [] { 2m, 4m, 6m, 12m, 24m }; ... s += 1m / hcc[i];

decimal in base-10, rather base-2, guarantee decimal precision, rather binary. has quite huge range, should plenty use.

oh, , if you've got 70-digit numbers there, how expect them impact number need precise 7 decimal digits? think you're missing point somewhere...

edit:

you're still missing crucial point - if working growing series of numbers, numbers digits above 20 have no impact on result anyway. sum of series converges on given number, , can approximate first n important digits (have @ taylor series how used e.g. compute sin (x), infinite decimal expression).

now, if series finite , isn't growing, simples thing can order before doing sum. input numbers in double - don't worry lost precision, not impact outcome (this takes bit of mathematical analysis, have no thought background is, if can't prove yourself, might want inquire question on math se). order them largest smallest. sum them 1 after another. result should quite precise 15 digits - you'll lose far decimal digits start adding larger 1 / x, not impact result anyway.

of course, if know this, can proving don't need count big numbers in first place - cannot impact decimals higer own digit count plus 1-2. exact behaviour much more pronounced if growth rate big (a simple illustration beingness geometric series g(n) = 2 ^ n), seems approximate case rather well, given you're working little , extremely big numbers in same series. if not enough, can seek doing partial sums of numbers close plenty add together precision on e.g. decimal, , adding sums - high-school algebra should plenty :)

all in all, doing math in head (or on paper) helps lot. infinite decimal look quite normal in math, , there's lot of tools work those. , approximation, rounding, limits , other stuff related this.

c# biginteger sharpdevelop

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -