Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by The-Oddler · Nov 28, 2012 at 06:22 PM · c#spaceinfinite

BigInteger/BigRational

Hi,

Is there something like BigInteger/BigRational for Unity (indie)? To be used with c# code.

I want to create a randomly generated space world, and even though double/decimal would be plenty of range, it would be nice that it could actually be infite.

Thanks,

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Eric5h5 · Nov 28, 2012 at 06:29 PM

http://biginteger.codeplex.com/

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image The-Oddler · Nov 28, 2012 at 06:32 PM 0
Share

Alright, so no build-in thing? This implementation of BigInteger looks like a real good one :D Thanks.

avatar image Eric5h5 · Nov 28, 2012 at 06:38 PM 0
Share

BigInteger is from .NET 4 and the version of $$anonymous$$ono currently used in Unity is approximately .NET 3.5.

avatar image The-Oddler · Nov 28, 2012 at 06:41 PM 0
Share

Yea, I knew that, that's why I was looking for something else. Also know a good implementation of a number with stuff behind the comma?

avatar image Radivarig · May 24, 2014 at 08:27 PM 0
Share

Thanks man!

avatar image
0

Answer by DeathApocalypse · Sep 25, 2018 at 07:55 PM

I made a simple class to do math with numbers in string format, it may be a strange alternative to BigInteger, but it works for me. https://dl.dropboxusercontent.com/s/uq6tkbmpimk92xe/StringMath.cs?dl=0

if you want to use it, simply copy the cs file to your assets folder, and use it this way:

 string a = "999999999999999999999";
 string b = "8888888888888888888888;"
 string c;
 c = StringMath.Add(a,b) // c = a+b
 c = StringMath.Sub(a,b) // c = a-b
 c = StringMath.Mult(a,b) // c = a*b
 c = StringMath.Dev(a,b) // c = a/b
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TheEugeneL · Jun 08, 2019 at 09:17 AM 1
Share

Thanks! It’s awesome. But unfortunately sometimes multiple and divide work is not correct.

avatar image Bunny83 TheEugeneL · Jun 08, 2019 at 12:59 PM 0
Share

Actually this implementation has several bugs which result in wrong calculations. Apart from that there's no problem doing calculations in BCD format. However using the string class is the least efficient way since any kind of operation on a string will result in a new string. So a quite long multiplication could probably allocate mega bytes of memory. Using byte or int arrays / Lists for the internal calculations would be way faster. Also they could be reused.


Concrete errors are:

  • In $$anonymous$$ult he doesn't do proper carrying for the last "a" (==0).

  • isZero returns pretty non sense. It will return true whenever the number doesn't contain a 9. He probably wanted to use output ||= inside the for loop. Though an early exit would make more sense.

  • he doesn't seem to support any negative numbers.

  • Some of the method don't seem to properly keep track of the current power of 10 while iterating.


It also has some bad style like not using break to ter$$anonymous$$ate a loop but ins$$anonymous$$d he messes with the for loop variable in order to ter$$anonymous$$ate the loop.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to make a game with lots of objects?!! 1 Answer

Help me with this Pathfinding? 1 Answer

Infinite Space in Cube 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges