Spyru Posted March 12, 2004 Posted March 12, 2004 I'd like to do some math with strings, with decimals behind the point (I don't know how to say that in English exactly). I mean this part: 2.23 grtz, Spyru Quote
Administrators PlausiblyDamp Posted March 12, 2004 Administrators Posted March 12, 2004 I'd like to do some math with strings' date=' with decimals behind the point (I don't know how to say that in English exactly). I mean this part: 2.[b']23[/b] grtz, Spyru Could you give a bit more detail? Do what with the numbers exactly? Also when you say math with strings - do you mean convert strings to numbers and then do math? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Spyru Posted March 12, 2004 Author Posted March 12, 2004 Not converting them to numbers and do math, because that would remove some of the decimals because the number will be too long. And I thought I once saw some code with which you could do math with strings so one can calculate with lots of decimals behind the point (2.2328745825784957945 etc.) Quote
Denaes Posted March 12, 2004 Posted March 12, 2004 As far as I know, Strings can't do math. You can hold your information in a string, then convert it to a number to do the math. Integers won't hold any decimal places. Doubles would hold more than enough I'd suppose... something like: -1.79769313486232E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values Quote
Administrators PlausiblyDamp Posted March 12, 2004 Administrators Posted March 12, 2004 What kind of precision are you look at? How many places before and after the decimal point do you require? Would a decimal data type not suffice? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Spyru Posted March 12, 2004 Author Posted March 12, 2004 Actually I'm going to calculate the square root of 5 :p and I'm going for lots of places after the decimal point, just for fun ;x And Denaes... It's possible, with some complex functions parsing it number by number. Quote
TechnoTone Posted March 12, 2004 Posted March 12, 2004 And Denaes... It's possible' date=' with some complex functions parsing it number by number.[/quote']You've just answered your own question there. You can do it but you'll have to write your own maths functions that can work on the string data directly. Personally, I'd have thought that it's be better to use an array rather than a string. I'd be very interested in seeing your final solution. Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
dragon4spy Posted March 13, 2004 Posted March 13, 2004 (edited) For 64bits number (decimal type?), it can hold as small as 0.0000000000000000001 (10^-19) and as big as 18,446,744,073,709,551,615 (2^64). I am doubt how Windows Calculator App can even compute much more places. Edited March 13, 2004 by dragon4spy Quote Don't judge a man by his look. Don't judge a book by its cover. :D
Leaders Iceplug Posted March 13, 2004 Leaders Posted March 13, 2004 A Double is 64 bits and a Decimal is 128 bits. :) From the documentation: 0 through +/-79,228,162,514,264,337,593,543,950,335 with no decimal point; 0 through +/-7.9228162514264337593543950335 with 28 places to the right of the decimal; smallest nonzero number is +/-0.0000000000000000000000000001 (+/-1E-28). I think it would be easier with an array also and then a conversion to string. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
*Experts* Nerseus Posted March 14, 2004 *Experts* Posted March 14, 2004 While a decimal CAN hold very large numbers, he might not get the precision. Meaning, though you can hold numbers with essentially 20 decimals, it might not work for what he wants. If your whole plan is to calculate a square root manually, then you don't want a numeric type at all - wouldn't that defeat the purpose of learning how to calculate the square root if the built in Math functions do it for you? If this is for a learning excersize, or if you just really need this functionality, I'd suggest creating your own class - maybe BigDecimal. Whether you store the final result in a string or array is up to you. By the way, this is a common problem brought up in College courses - if you just want to see how it's done, I'm sure you can search Google and find some code in existence that will give you the base for what you need/want. It will probably be in C++, but I'm sure you could convert it. -nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
dragon4spy Posted March 14, 2004 Posted March 14, 2004 While a decimal CAN hold very large numbers, he might not get the precision. Meaning, though you can hold numbers with essentially 20 decimals, it might not work for what he wants. :) Decimal is the most precise number type. You can take a deep look at Iceplug's quote. Can someone show how to use array to extend the number places? :D Quote Don't judge a man by his look. Don't judge a book by its cover. :D
Leaders Iceplug Posted March 16, 2004 Leaders Posted March 16, 2004 You can easily use an array of digits (numbers 0 through 9) and just use your lower school knowledge to add them together: 2338 + 4055 NumberArray1 = (2) (3) (3) (8) NumberArray2 = (4) (0) (5) (5) (8)+(5) = 13 13 \ 10 = 1, so carry 1 into next column and store 13 Mod 10 = 3 in this column (2) (3) (4) (8) (4) (0) (5) (5) (?) (?) (?) (3) You can continue the process iteratively... (6) (3) (9) (3) And as you can see, we can store numbers larger than 9 in most Integer data types (even a byte can hold up to 255)... so, you could, with Integers, do something like this: (2020202020)(2020202020)(2020202018) +(4040404040)(5050505050)(6060606041) =(6060606060)(7070707070)(8080808059) And I have just performed an addition with: 202020202020202020202020202018 + 404040404050505050506060606041 :). Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Hamburger1984 Posted March 16, 2004 Posted March 16, 2004 I know this doesn't really answer the question but would 5000 numbers after the dot be enough? here you go: 2.2360679774984977140529041149197687930865821946597093896365381741877712311434895388224013140567740465187277814864622267801416609961418931920378307313418235332690494695506256926908816886661528257488048898735714846240092706361415061988779348325018355300570062424146653207904550287073675972777181163322938267066129606159211135943172204431286677007983883884852335234974721821791799829938005845746676427494144041004075252969903756951095889380155205756738249651437410843763336483027662486065558791248364685154189899693522916982442335331723011795766509826938808856553460417587119147669064949277021528644481208794634554834243304749588551022360679774984977140529041149197687930865821946597093896365381741877712311434895388224013140567740465187277814864622267801416609961418931920378307313418235332690494695506256926908816886661528257488048898735714846240092706361415061988779348325018355300570062424146653207904550287073675972777181163322938267066129606159211135943172204431286677007983883884852335234974721821791799829938005845746676427494144041004075252969903756951095889380155205756738249651437410843763336483027662486065558791248364685154189899693522916982442335331723011795766509826938808856553460417587119147669064949277021528644481208794634554834243304749588551022360679774984977140529041149197687930865821946597093896365381741877712311434895388224013140567740465187277814864622267801416609961418931920378307313418235332690494695506256926908816886661528257488048898735714846240092706361415061988779348325018355300570062424146653207904550287073675972777181163322938267066129606159211135943172204431286677007983883884852335234974721821791799829938005845746676427494144041004075252969903756951095889380155205756738249651437410843763336483027662486065558791248364685154189899693522916982442335331723011795766509826938808856553460417587119147669064949277021528644481208794634554834243304749588551022360679774984977140529041149197687930865821946597093896365381741877712311434895388224013140567740465187277814864622267801416609961418931920378307313418235332690494695506256926908816886661528257488048898735714846240092706361415061988779348325018355300570062424146653207904550287073675972777181163322938267066129606159211135943172204431286677007983883884852335234974721821791799829938005845746676427494144041004075252969903756951095889380155205756738249651437410843763336483027662486065558791248364685154189899693522916982442335331723011795766509826938808856553460417587119147669064949277021528644481208794634554834243304749588551022360679774984977140529041149197687930865821946597093896365381741877712311434895388224013140567740465187277814864622267801416609961418931920378307313418235332690494695506256926908816886661528257488048898735714846240092706361415061988779348325018355300570062424146653207904550287073675972777181163322938267066129606159211135943172204431286677007983883884852335234974721821791799829938005845746676427494144041004075252969903756951095889380155205756738249651437410843763336483027662486065558791248364685154189899693522916982442335331723011795766509826938808856553460417587119147669064949277021528644481208794634554834243304749588551022360679774984977140529041149197687930865821946597093896365381741877712311434895388224013140567740465187277814864622267801416609961418931920378307313418235332690494695506256926908816886661528257488048898735714846240092706361415061988779348325018355300570062424146653207904550287073675972777181163322938267066129606159211135943172204431286677007983883884852335234974721821791799829938005845746676427494144041004075252969903756951095889380155205756738249651437410843763336483027662486065558791248364685154189899693522916982442335331723011795766509826938808856553460417587119147669064949277021528644481208794634554834243304749588551022360679774984977140529041149197687930865821946597093896365381741877712311434895388224013140567740465187277814864622267801416609961418931920378307313418235332690494695506256926908816886661528257488048898735714846240092706361415061988779348325018355300570062424146653207904550287073675972777181163322938267066129606159211135943172204431286677007983883884852335234974721821791799829938005845746676427494144041004075252969903756951095889380155205756738249651437410843763336483027662486065558791248364685154189899693522916982442335331723011795766509826938808856553460417587119147669064949277021528644481208794634554834243304749588551022360679774984977140529041149197687930865821946597093896365381741877712311434895388224013140567740465187277814864622267801416609961418931920378307313418235332690494695506256926908816886661528257488048898735714846240092706361415061988779348325018355300570062424146653207904550287073675972777181163322938267066129606159211135943172204431286677007983883884852335234974721821791799829938005845746676427494144041004075252969903756951095889380155205756738249651437410843763336483027662486065558791248364685154189899693522916982442335331723011795766509826938808856553460417587119147669064949277021 calculated using DERIVE5 - the math program we used at school.. works pretty well... Andreas Quote
Kurt Posted May 20, 2004 Posted May 20, 2004 http://mathforum.org/dr.math/faq/faq.sqrt.by.hand.html Quote qrt
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.