GithubHelp home page GithubHelp logo

How to use as scaled decimal number (1.x) about cnl HOT 6 OPEN

vrqq avatar vrqq commented on June 12, 2024
How to use as scaled decimal number (1.x)

from cnl.

Comments (6)

johnmcfarlane avatar johnmcfarlane commented on June 12, 2024

Hi. Thanks for filing this issue. It has since been addressed in the latest version:
1.x: https://godbolt.org/z/1Y53M5Knj
2.x: https://godbolt.org/z/exxafsKjx
Is it possible for you to upgrade?

I am confusing that why can't be default_scale<(Digits < 0), (Radix != 2)>?

The specialisation that was provided in v1 is likely to be using a bit shift operation and so only works for the binary base.

from cnl.

vrqq avatar vrqq commented on June 12, 2024

Still in v1 since the C++17 we used.
I try to add these code in cnl/_impl/num_traits/scale.h
( https://github.com/johnmcfarlane/cnl/blob/v1.x/include/cnl/_impl/num_traits/scale.h#L48 )
And then the problem solved.

namespace cnl {
    template<int Digits, int Radix, template<typename, typename> class TNUM, typename S, typename Tag>
    struct scale<Digits, Radix, TNUM<S, Tag>, _impl::enable_if_t<(
        Digits<0 && cnl::_impl::is_integral<S>::value)>>
    {
        CNL_NODISCARD constexpr auto operator()(TNUM<S, Tag> const& s) const
        -> decltype(s/_impl::power_value<S, -Digits, Radix>())
        {
            return s/_impl::power_value<S, -Digits, Radix>();
        }
    };
}

Could you please help me to review these code?

  • Is that a right change?
  • Any other improvement suggestion?

from cnl.

johnmcfarlane avatar johnmcfarlane commented on June 12, 2024

Hi. Thanks for the feedback and suggestion. I should be able to take a look at it later today.

The great thing about DVCS and CI is that you can safely break things without causing harm or disruption to others. So while I'm happy to help, you don't have to wait.

  1. fork the project under your own user account,
  2. See whether GitHub Actions runs and builds the project for you (it may not or there may have been degradations in the build system over the past few months; I'm not sure),
  3. make a branch off of v1.x,
  4. add a test which fails - it doesn't have to be perfect or ready for merging but shows the problem,
  5. apply the change,
  6. push the branch to GitHub,
  7. see whether the fix prevents the test from failing.

from cnl.

johnmcfarlane avatar johnmcfarlane commented on June 12, 2024

CI for v1.x is not currently working, likely due to updates to the docker images used to build the project. I'll need to fix the v1.x branch first.

from cnl.

johnmcfarlane avatar johnmcfarlane commented on June 12, 2024

Test case pushed and confirmed.

Fix pushed but breaking.

@vrqq did you add the specialisation of cnl::scale or did you replace an existing specialisation?

from cnl.

vrqq avatar vrqq commented on June 12, 2024

After one years I retry to fix this issue, and there still some bug I cannot fixed. (I made a pull request into 991 branch it into branch)
The code previous I posted, was break the coding style of template partial specialization. For the third argument, I should keep it fixed on the special type, instead of using template<typename, typename> to match any _impl::number type.

After reading the code in project, I found out the design-rule of struct scale. The third argument class Rep should be specialized in different files, such as rouding_integer.h

So It may more suitable to move into https://github.com/johnmcfarlane/cnl/blob/991/include/cnl/rounding_integer.h#L74

There's some problem on test like std::hash<path> in cppcon2017.cpp. In the code below, there still have problem on GCC and Clang compiler.
https://github.com/johnmcfarlane/cnl/blob/main/test/unit/presentations/cppcon2017.cpp#L23

And conan in pip has been updated into 2.0, but a lot of package hasn't upgraded in there repo.

from cnl.

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.