GithubHelp home page GithubHelp logo

Comments (9)

ckormanyos avatar ckormanyos commented on August 14, 2024

can use wide-decimal type how a integer type?

Hi Daniel. Thank you for your query.

Unfortunately, I would not generally recommend using wide-decimal (i.e., decwide-t) as an integer type. You can perform some floating-point decimal calculations and convert the results to integer. But wide-decimal is not really intended nor tested to be an integer representation.

You can do pure signed/unsigned integer calculations with my other repository wide-integer. But there is at the moment no inter-conversion between wide-decimal's decwide_t and wide_integer's uintwide_t.

Boost.Multiprecision is another option with much more interoperability amongh the multiprecision types --- that might be another option, but it might not yet have huge precision if that is what you seek. And Boost tends to have a larger resource footprint than my repos here. (I am also a Boost.Multiprecision co-author/co-maintainer).

If you would like to discuss these matters, or if you have direct questions as you try things or discover bugs I can easily fix or at least try to fix, please feel free to continue this thread.

from wide-decimal.

danieagle avatar danieagle commented on August 14, 2024

Great!!!

I'll route to wide-integer + wide-decimal.

I afraid from boost.multiprecision cpp_dec_float in doc say raw "truncate number" with no choose for rounding type,
but boost.multiprecision cpp_int is really good

I'm planning to use arbitrary fixed int and uint to use as 'id' in databases and decimal arbitrary fixed type to compute
and use money values. for decimal fixed point, my consumption dream is some similar at Ada Language 'fixed decimal type' but com more than 18 digits (and in C++20). https://en.wikibooks.org/wiki/Ada_Programming/Types/delta#Decimal_Fixed_Point

And a BigThanks for all your efforts and help!

Thanks,
Best whishes, Daniel

from wide-decimal.

ckormanyos avatar ckormanyos commented on August 14, 2024

afraid from boost.multiprecision cpp_dec_float in doc say raw "truncate number" with no choose for rounding type

Yes. But please do note that the decwide_t implementation in wide-decimal also has this characteristic. There is rounding on the functions floor, ceil and cast-to-integral-type. But both the Boost decimal type as well as the one in wide-integer do not have complete rounding implemented. I'm pretty sure that Boot.Multiprecision and also wide-decimal will eventually have rounnding on the decimal type, but that's still a ways off at the moment.

In your search for well-behaved decimal numbers, you might also look at cnl from @johnmcfarlane. John do you have a well-behaved decimal type?

from wide-decimal.

ckormanyos avatar ckormanyos commented on August 14, 2024

See also #49 in this repo

from wide-decimal.

danieagle avatar danieagle commented on August 14, 2024

Hi!

This is a really good news!

To exemplify, my main need is a type where I can:
a) set a fixed number of decimal places after the comma.
b) the smallest possible value being 0, 0{decimal places - 1}1 .
c) not limited to 64bit.

eg: 20 digits (comma) 6 digits .

For that I'll create a 20digits (comma) 12digits.
The double digits after comma is to
is to deal with precision and with round. even if it is raw truncated it will still be in
the desired range.

Very thanks for the help,
Best whishes, Daniel.

from wide-decimal.

ckormanyos avatar ckormanyos commented on August 14, 2024

For that I'll create a 20digits (comma) 12digits

Cool @danieagle. That seems like a good plan. If any further issues arise, please feel free to get back to this issue or create a new one. For the moment, I'll close this.

Thanks for your interest in decwide-t.

from wide-decimal.

johnmcfarlane avatar johnmcfarlane commented on August 14, 2024

afraid from boost.multiprecision cpp_dec_float in doc say raw "truncate number" with no choose for rounding type

Yes. But please do note that the decwide_t implementation in wide-decimal also has this characteristic. There is rounding on the functions floor, ceil and cast-to-integral-type. But both the Boost decimal type as well as the one in wide-integer do not have complete rounding implemented. I'm pretty sure that Boot.Multiprecision and also wide-decimal will eventually have rounnding on the decimal type, but that's still a ways off at the moment.

In your search for well-behaved decimal numbers, you might also look at cnl from @johnmcfarlane. John do you have a well-behaved decimal type?

Hi there. When you can get it to compile, it's generally well behaved: https://godbolt.org/z/WT6K6aT7W
I definitely need more operators to make this user-friendly though.

from wide-decimal.

danieagle avatar danieagle commented on August 14, 2024

Hi @ckormanyos and @johnmcfarlane !
Thanks for yours patience and dedication!

I see the updates and tried again.
I getted great success , while not touch the max or min from the setted range, using
cnl with wide_integer port in cnl.
wi_si.cpp.txt

but I yet get funny values when the number reach max or minimum values;

(Whishlist) (pleeaaaaase! :-)

  1. add round 'nearest to even' (mostly banks use this round type).
  2. and add some way to detect overflow and underflow.
  3. (optional) add initialization with strings.

My Sincere Gratitude,
Best wishes, Daniel.

My System:
Linux Ubuntu impish AMD64 g++-11.2.0 cmake-3.18.4 bash-5.1.3
cmdline: g++ -O3 -mtune=native -std=c++20 wi_si.cpp -o Eba1
cmdline: ./Eba1

I am available for testing or whatever is needed.

from wide-decimal.

ckormanyos avatar ckormanyos commented on August 14, 2024

Hi @danieagle I will keep trying to move forward on implementing rounding for wide-decimal. This is being tracked in #49.

I have tried a few times and failed. So I'm not quite comprehending all rounding cases and/or algoritmic details. If I get rounding in wide-decimal, i'll probably import the technology into Boost.Multiprecision and vice versa. But this will take me a while --- if I get it at all.

cnl from @johnmcfarlane is a good place to also keep track of regarding progress on decimal type(s). Formally, John's cnl development is independent of this project, but we are in contact off-and-on regarding related topics.

from wide-decimal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.