473,395 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Custom ValueType to Accept 128-bits

Greetings,

I know I can create class that "implicit"ly accepts an 8-bit to 64-bit
value. Without using double, or single, I would like to create my own
"unsigned" 128-bit valuetype (to be used with my Binary objects I recently
created http://www.visualassembler.com/binary) but I don't know how I can do
so. How can I make it accept the number 2309823982039203948203948? I don't
want to have to pass the numbers as a string, I just want to assign it a
number and expect that it'll work.

I know I can use 64-bit because I just implicit with a ulong as a parameter
type, but I don't know how to go about creating my own 128-bit type...

Any ideas?

Thanks,
Shawn
Nov 15 '05 #1
4 2647
Hi Shawn,

I don't think you'll ever get a statement like the following to compile:
Binary128 b = 2309823982039203948203948;
The compiler will have no idea what you're talking about. :)
Perhaps a Binary128 could consist of two Binary64 with some logic to hide that,
but I don't think that you'll be able to initialize it with a value bigger than 64bits, unless it's initialized with another
Binary128.

--
Robert Jeppesen
robert.jeppesen%at%durius-dot-se
"Shawn B." <le****@html.com> wrote in message news:uQ**************@tk2msftngp13.phx.gbl...
Greetings,

I know I can create class that "implicit"ly accepts an 8-bit to 64-bit
value. Without using double, or single, I would like to create my own
"unsigned" 128-bit valuetype (to be used with my Binary objects I recently
created http://www.visualassembler.com/binary) but I don't know how I can do
so. How can I make it accept the number 2309823982039203948203948? I don't
want to have to pass the numbers as a string, I just want to assign it a
number and expect that it'll work.

I know I can use 64-bit because I just implicit with a ulong as a parameter
type, but I don't know how to go about creating my own 128-bit type...

Any ideas?

Thanks,
Shawn

Nov 15 '05 #2
You can do this with two 64 bit values, but you'll have to write a lot of
code. Mathematical operations will be quite difficult, as there is no
overflow bit (and a checked overflow condition throws an exception, which
would kill your performance on simple mathematical operations).

I haven't seen a good arbitrary-precision integer library for C#, but maybe
you should be looking for something along those lines, perhaps in the C/C++
world.

"Shawn B." <le****@html.com> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl...
Greetings,

I know I can create class that "implicit"ly accepts an 8-bit to 64-bit
value. Without using double, or single, I would like to create my own
"unsigned" 128-bit valuetype (to be used with my Binary objects I recently
created http://www.visualassembler.com/binary) but I don't know how I can do so. How can I make it accept the number 2309823982039203948203948? I don't want to have to pass the numbers as a string, I just want to assign it a
number and expect that it'll work.

I know I can use 64-bit because I just implicit with a ulong as a parameter type, but I don't know how to go about creating my own 128-bit type...

Any ideas?

Thanks,
Shawn

Nov 15 '05 #3
I was looking in the Mono source code and they have a
Corlib.Mono.Math.BigInteger object that takes 160 bits of memory. It is a
rather interesting piece of work. There is a possibility my answer lies in
in examining that source code.
Thanks,
Shawn

"Shawn B." <le****@html.com> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl...
Greetings,

I know I can create class that "implicit"ly accepts an 8-bit to 64-bit
value. Without using double, or single, I would like to create my own
"unsigned" 128-bit valuetype (to be used with my Binary objects I recently
created http://www.visualassembler.com/binary) but I don't know how I can do so. How can I make it accept the number 2309823982039203948203948? I don't want to have to pass the numbers as a string, I just want to assign it a
number and expect that it'll work.

I know I can use 64-bit because I just implicit with a ulong as a parameter type, but I don't know how to go about creating my own 128-bit type...

Any ideas?

Thanks,
Shawn

Nov 15 '05 #4
100
Hi,
If you don't want to use strings for initializing your "big" value type the
compiler has to support such a big litterals.
I'm not sure MS c# compiler can handle those litterals. Maybe in the MONO
project they have modified their compiler.

B\rgds
100

"Shawn B." <le****@html.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I was looking in the Mono source code and they have a
Corlib.Mono.Math.BigInteger object that takes 160 bits of memory. It is a
rather interesting piece of work. There is a possibility my answer lies in in examining that source code.
Thanks,
Shawn

"Shawn B." <le****@html.com> wrote in message
news:uQ**************@tk2msftngp13.phx.gbl...
Greetings,

I know I can create class that "implicit"ly accepts an 8-bit to 64-bit
value. Without using double, or single, I would like to create my own
"unsigned" 128-bit valuetype (to be used with my Binary objects I recently created http://www.visualassembler.com/binary) but I don't know how I
can do
so. How can I make it accept the number 2309823982039203948203948? I

don't
want to have to pass the numbers as a string, I just want to assign it a
number and expect that it'll work.

I know I can use 64-bit because I just implicit with a ulong as a

parameter
type, but I don't know how to go about creating my own 128-bit type...

Any ideas?

Thanks,
Shawn


Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Brian Brane | last post by:
I have properties that wrap DataRow columns as in: public int aNumber { get{ return m_DataRow; } set{ m_DataRow = value; } } If the column happens to contain DBNull, I get a cast exception...
2
by: Eric Newton | last post by:
Since String.Format has to box all value types to accomodate the params, and just for sheer efficiency, are there possibly any plans for a FormatValue method to minimize boxing? public static...
3
by: Laura T. | last post by:
The following code is driving me so crazy, that I'm thinking it's a "feature" or a.. ....dare I say it... a BUG. I'm using VS 2003. I've created a new value type (struct) called MyInt. MyInt has...
6
by: Sahil Malik | last post by:
Okay, I can't inherit from System.ValueType. Why this restriction?? What I am trying to acheive is, create my own ValueType called "Money". So if I have a decimal that has value 1.93991, when...
6
by: Aryeh Holzer | last post by:
Let me start with a quote from the C# Programmers Reference (where I learned the cool word "covariance"): "When a delegate method has a return type that is more derived than the delegate...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
3
by: ECathell | last post by:
Below is the code for a custom form control. Everything is good except I am getting the above error. I have Highlighted the relevant code below. I can't find the problem..Can anyone help me? I am...
6
by: Manikkoth | last post by:
Hello, Just curious to see why ValueType (which the base for all value types) is a class. I thought "class" would make a type a reference type. However, IsValueType for ValueType is returning...
2
by: Ravi Shekhar | last post by:
Hello, So I'm doing some mathematical modeling and it turns out I need distinct imaginary and complex types to carry out complex contour integration. I want to have it in all three precisions...
1
by: lbelkova | last post by:
Hello, I've created a custom DataGridViewColumn. Everything work well, except for some reason the column doesn't accept some of the chars: "q", "." and "'". Did anybody have a similar problem?...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.