|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
writing custom data type
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||||
|
New to Overclock.net
|
okay so i was wondering about some how figuring out how to allocate a really large amount of storage for a variable....like i want to be able to find really big Fibonacci numbers...etc...
i wanted to make a 128bit allocation(an extended double)....like extend the data type header file....
__________________
x2 4600+ @2.6ghz x2 6400+ @ 3.5ghz Quote:
Quote:
Quote:
|
|||||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||||
|
2 + 2 = 5
![]()
Join Date: Nov 2006
Location: In a Chair.
Posts: 34,851
Rep: 4164
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Unique Rep: 1903
Trader Rating: 56
|
Language?
__________________
To answer most of your questions: (1) a fridge cannot cool a PC (2) 64-bit OS for over 3.4GB (3) If a PCIe card fits, it should work (4) Resolution, not screen size (5) If you have a question, it is not news (6) Report, not respond to Spam (7) Single-Rail/Non-Modular PSUs are not always better than Multi-Rail/Modular
|
|||||||||||||
|
|
|
|
#3 (permalink) | |||||||||||||||
|
New to Overclock.net
|
i am sorry in C and java
__________________
x2 4600+ @2.6ghz x2 6400+ @ 3.5ghz Quote:
Quote:
Quote:
|
|||||||||||||||
|
|
|
|
|
#4 (permalink) | |||||||||||||
|
With great difficulty
![]() |
malloc lets you allocate arbitrary amounts of memory in C. You could also create a suitably sized struct
__________________In java, just make a class that does what you need. For large numbers, look at the BigInteger class
|
|||||||||||||
|
|
|
|
#5 (permalink) | |||||||||||||||
|
New to Overclock.net
|
thanks....i thought it would be something like malloc....
so i would just do Code:
#include <stdlib.h>
#define MAX_SIZE 1000
static void main(){
static int array[MAX_SIZE];
int i = 2;
array[0] = 1;
array[1] = 1;
fib = malloc(......); <---whatever the size i wish to make fib....
fib = array[i-1] + array[i-2];
array[i] = fib;
}
__________________
x2 4600+ @2.6ghz x2 6400+ @ 3.5ghz Quote:
Quote:
Quote:
|
|||||||||||||||
|
|
|
|
|
#6 (permalink) | ||||||||||||||
|
With great difficulty
![]() |
Quote:
|
||||||||||||||
|
|
|
|
#7 (permalink) | |||||||||||||||
|
New to Overclock.net
|
okay soo i was kindof not thinking when i wrote that little code...i think what i wanted was this....i hope this kindof half way looks like it should work...
type_def struct{ long double* num = malloc(2^128);////<---want to allocate 128bits }fib_array; static int main(){ static int i = 2; fib_array array[MAX_SIZE]; fib_array fib; array[0].num = 1; array[1].num = 1; while(i != MAX_SIZE){ fib.num = array[i-1].num + array[i-2].num; array = fib.num; i++; } for(i=0; i < MAX_SIZE; i++){ printf("%fib_num", array[i]); ///<---i don't think i formatted this correctly } }
__________________
x2 4600+ @2.6ghz x2 6400+ @ 3.5ghz Quote:
Quote:
Quote:
|
|||||||||||||||
|
|
|
|
|
#8 (permalink) | |||||||||||||||
|
With great difficulty
![]() |
Quote:
Code:
typedef struc{
Quote:
One last point. If you're working with the fibonacci sequence you're working entirely with integers, so you should use a long instead of a double. double's are not precise, so once you get beyond a certain range it no longer stores all the digits in the number
Last edited by rabidgnome229 : 03-19-09 at 03:12 PM |
|||||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|