Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

I recently had my interest in fixed point math piqued as part of a side project I was doing, so this is great to see! Having a C++ class for fixed point numbers would make things so easy!

I'm guessing that the weird formatting is due to copy/paste issues and that your actual code uses indentation. If not, it definitely should.

Description

#Description II notice throughout your comments you say "decimal part". However, you don't use any decimal representation. I was thinking that maybe you were working in BCD or something like that. I would change all references to "decimal" to be "fractional" to be more precise.

Don't Use using namespace std

#Don't Use using namespace std You'veYou've written:

using namespace std;

in your (削除) header (削除ここまで) main.cpp file. (削除) That means that every file which includes your header now has all of the std namespace defined, too. If I have my own max() function that's not in std and I include your header, I will now get conflicts on my max() function. (削除ここまで) See here for more details on why this isn't a good idea.

Usage

#Usage SeeingSeeing the examples of how to use this type in your example main.cpp file left me very confused, even with a comment describing the range. The way you have it now, I have to know how many bits are in a given type's representation, then subtract from that the number of bits I want for the fractional part in order to figure out the range I'll end up with. I also have to make sure that the type I supply has enough bits for the representation. (What happens if I do using Nbr32 = FixedPointNumber<uint8_t, 17>;?)

Furthermore, the type I supply may be unsigned, but the range of the resulting type can still cover negative values. Does it make sense to have an unsigned fixed point type and a signed fixed point type? I'm not sure. But it is odd to supply an unsigned type and have it end up being signed.

I'm not an expert at templates, so I'm not entirely sure what's possible. I think it would be better to have the template take the number of bits for the integral part and the number of bits for the fractional part and choose the type it uses internally based on that and not require a caller to figure it out.

In other words, I'd like to use it like this:

using Fixed16_16 = FixedPointNumber<16, 16>;
using Fixed8_4 = FixedPointNumber<8, 4>;

As I say, I don't know whether it's possible to make that work, but it sure would be nice. If you can get closer to that, it would be great.

Naming

#Naming I'mI'm all for long descriptive names. However, I do feel like FixedPointNumber is too long. We don't call float a floatingPointNumber or int an intNumber. I think it would be fine as FixedPoint or even Fixed (though be aware that Apple has used that type name in the past for 16.16 fixed point numbers).

Future Directions

#Future Directions I'dI'd love to see a whole math library for this type. Things like trigonometric and transcendental functions would be helpful. (You might look into cordics if you plan to pursue something like that.)

I recently had my interest in fixed point math piqued as part of a side project I was doing, so this is great to see! Having a C++ class for fixed point numbers would make things so easy!

I'm guessing that the weird formatting is due to copy/paste issues and that your actual code uses indentation. If not, it definitely should.

#Description I notice throughout your comments you say "decimal part". However, you don't use any decimal representation. I was thinking that maybe you were working in BCD or something like that. I would change all references to "decimal" to be "fractional" to be more precise.

#Don't Use using namespace std You've written:

using namespace std;

in your (削除) header (削除ここまで) main.cpp file. (削除) That means that every file which includes your header now has all of the std namespace defined, too. If I have my own max() function that's not in std and I include your header, I will now get conflicts on my max() function. (削除ここまで) See here for more details on why this isn't a good idea.

#Usage Seeing the examples of how to use this type in your example main.cpp file left me very confused, even with a comment describing the range. The way you have it now, I have to know how many bits are in a given type's representation, then subtract from that the number of bits I want for the fractional part in order to figure out the range I'll end up with. I also have to make sure that the type I supply has enough bits for the representation. (What happens if I do using Nbr32 = FixedPointNumber<uint8_t, 17>;?)

Furthermore, the type I supply may be unsigned, but the range of the resulting type can still cover negative values. Does it make sense to have an unsigned fixed point type and a signed fixed point type? I'm not sure. But it is odd to supply an unsigned type and have it end up being signed.

I'm not an expert at templates, so I'm not entirely sure what's possible. I think it would be better to have the template take the number of bits for the integral part and the number of bits for the fractional part and choose the type it uses internally based on that and not require a caller to figure it out.

In other words, I'd like to use it like this:

using Fixed16_16 = FixedPointNumber<16, 16>;
using Fixed8_4 = FixedPointNumber<8, 4>;

As I say, I don't know whether it's possible to make that work, but it sure would be nice. If you can get closer to that, it would be great.

#Naming I'm all for long descriptive names. However, I do feel like FixedPointNumber is too long. We don't call float a floatingPointNumber or int an intNumber. I think it would be fine as FixedPoint or even Fixed (though be aware that Apple has used that type name in the past for 16.16 fixed point numbers).

#Future Directions I'd love to see a whole math library for this type. Things like trigonometric and transcendental functions would be helpful. (You might look into cordics if you plan to pursue something like that.)

I recently had my interest in fixed point math piqued as part of a side project I was doing, so this is great to see! Having a C++ class for fixed point numbers would make things so easy!

I'm guessing that the weird formatting is due to copy/paste issues and that your actual code uses indentation. If not, it definitely should.

Description

I notice throughout your comments you say "decimal part". However, you don't use any decimal representation. I was thinking that maybe you were working in BCD or something like that. I would change all references to "decimal" to be "fractional" to be more precise.

Don't Use using namespace std

You've written:

using namespace std;

in your (削除) header (削除ここまで) main.cpp file. (削除) That means that every file which includes your header now has all of the std namespace defined, too. If I have my own max() function that's not in std and I include your header, I will now get conflicts on my max() function. (削除ここまで) See here for more details on why this isn't a good idea.

Usage

Seeing the examples of how to use this type in your example main.cpp file left me very confused, even with a comment describing the range. The way you have it now, I have to know how many bits are in a given type's representation, then subtract from that the number of bits I want for the fractional part in order to figure out the range I'll end up with. I also have to make sure that the type I supply has enough bits for the representation. (What happens if I do using Nbr32 = FixedPointNumber<uint8_t, 17>;?)

Furthermore, the type I supply may be unsigned, but the range of the resulting type can still cover negative values. Does it make sense to have an unsigned fixed point type and a signed fixed point type? I'm not sure. But it is odd to supply an unsigned type and have it end up being signed.

I'm not an expert at templates, so I'm not entirely sure what's possible. I think it would be better to have the template take the number of bits for the integral part and the number of bits for the fractional part and choose the type it uses internally based on that and not require a caller to figure it out.

In other words, I'd like to use it like this:

using Fixed16_16 = FixedPointNumber<16, 16>;
using Fixed8_4 = FixedPointNumber<8, 4>;

As I say, I don't know whether it's possible to make that work, but it sure would be nice. If you can get closer to that, it would be great.

Naming

I'm all for long descriptive names. However, I do feel like FixedPointNumber is too long. We don't call float a floatingPointNumber or int an intNumber. I think it would be fine as FixedPoint or even Fixed (though be aware that Apple has used that type name in the past for 16.16 fixed point numbers).

Future Directions

I'd love to see a whole math library for this type. Things like trigonometric and transcendental functions would be helpful. (You might look into cordics if you plan to pursue something like that.)

Fixed my mistake about where `using namespace std;` was located.
Source Link
user1118321
  • 11.9k
  • 1
  • 20
  • 46

I recently had my interest in fixed point math piqued as part of a side project I was doing, so this is great to see! Having a C++ class for fixed point numbers would make things so easy!

I'm guessing that the weird formatting is due to copy/paste issues and that your actual code uses indentation. If not, it definitely should.

#Description I notice throughout your comments you say "decimal part". However, you don't use any decimal representation. I was thinking that maybe you were working in BCD or something like that. I would change all references to "decimal" to be "fractional" to be more precise.

#Don't Use using namespace std You've written:

using namespace std;

in your header file. That means that every file which includes your header now has all of the std namespace defined, too. If I have my own max() function that's not in std and I include your header, I will now get conflicts on my(削除) header (削除ここまで) max()main.cpp functionfile. (削除) That means that every file which includes your header now has all of the std namespace defined, too. If I have my own max() function that's not in std and I include your header, I will now get conflicts on my max() function. (削除ここまで)See here for more details on why this isn't a good idea.

#Usage Seeing the examples of how to use this type in your example main.cpp file left me very confused, even with a comment describing the range. The way you have it now, I have to know how many bits are in a given type's representation, then subtract from that the number of bits I want for the fractional part in order to figure out the range I'll end up with. I also have to make sure that the type I supply has enough bits for the representation. (What happens if I do using Nbr32 = FixedPointNumber<uint8_t, 17>;?)

Furthermore, the type I supply may be unsigned, but the range of the resulting type can still cover negative values. Does it make sense to have an unsigned fixed point type and a signed fixed point type? I'm not sure. But it is odd to supply an unsigned type and have it end up being signed.

I'm not an expert at templates, so I'm not entirely sure what's possible. I think it would be better to have the template take the number of bits for the integral part and the number of bits for the fractional part and choose the type it uses internally based on that and not require a caller to figure it out.

In other words, I'd like to use it like this:

using Fixed16_16 = FixedPointNumber<16, 16>;
using Fixed8_4 = FixedPointNumber<8, 4>;

As I say, I don't know whether it's possible to make that work, but it sure would be nice. If you can get closer to that, it would be great.

#Naming I'm all for long descriptive names. However, I do feel like FixedPointNumber is too long. We don't call float a floatingPointNumber or int an intNumber. I think it would be fine as FixedPoint or even Fixed (though be aware that Apple has used that type name in the past for 16.16 fixed point numbers).

#Future Directions I'd love to see a whole math library for this type. Things like trigonometric and transcendental functions would be helpful. (You might look into cordics if you plan to pursue something like that.)

I recently had my interest in fixed point math piqued as part of a side project I was doing, so this is great to see! Having a C++ class for fixed point numbers would make things so easy!

I'm guessing that the weird formatting is due to copy/paste issues and that your actual code uses indentation. If not, it definitely should.

#Description I notice throughout your comments you say "decimal part". However, you don't use any decimal representation. I was thinking that maybe you were working in BCD or something like that. I would change all references to "decimal" to be "fractional" to be more precise.

#Don't Use using namespace std You've written:

using namespace std;

in your header file. That means that every file which includes your header now has all of the std namespace defined, too. If I have my own max() function that's not in std and I include your header, I will now get conflicts on my max() function. See here for more details.

#Usage Seeing the examples of how to use this type in your example main.cpp file left me very confused, even with a comment describing the range. The way you have it now, I have to know how many bits are in a given type's representation, then subtract from that the number of bits I want for the fractional part in order to figure out the range I'll end up with. I also have to make sure that the type I supply has enough bits for the representation. (What happens if I do using Nbr32 = FixedPointNumber<uint8_t, 17>;?)

Furthermore, the type I supply may be unsigned, but the range of the resulting type can still cover negative values. Does it make sense to have an unsigned fixed point type and a signed fixed point type? I'm not sure. But it is odd to supply an unsigned type and have it end up being signed.

I'm not an expert at templates, so I'm not entirely sure what's possible. I think it would be better to have the template take the number of bits for the integral part and the number of bits for the fractional part and choose the type it uses internally based on that and not require a caller to figure it out.

In other words, I'd like to use it like this:

using Fixed16_16 = FixedPointNumber<16, 16>;
using Fixed8_4 = FixedPointNumber<8, 4>;

As I say, I don't know whether it's possible to make that work, but it sure would be nice. If you can get closer to that, it would be great.

#Naming I'm all for long descriptive names. However, I do feel like FixedPointNumber is too long. We don't call float a floatingPointNumber or int an intNumber. I think it would be fine as FixedPoint or even Fixed (though be aware that Apple has used that type name in the past for 16.16 fixed point numbers).

#Future Directions I'd love to see a whole math library for this type. Things like trigonometric and transcendental functions would be helpful. (You might look into cordics if you plan to pursue something like that.)

I recently had my interest in fixed point math piqued as part of a side project I was doing, so this is great to see! Having a C++ class for fixed point numbers would make things so easy!

I'm guessing that the weird formatting is due to copy/paste issues and that your actual code uses indentation. If not, it definitely should.

#Description I notice throughout your comments you say "decimal part". However, you don't use any decimal representation. I was thinking that maybe you were working in BCD or something like that. I would change all references to "decimal" to be "fractional" to be more precise.

#Don't Use using namespace std You've written:

using namespace std;

in your (削除) header (削除ここまで) main.cpp file. (削除) That means that every file which includes your header now has all of the std namespace defined, too. If I have my own max() function that's not in std and I include your header, I will now get conflicts on my max() function. (削除ここまで)See here for more details on why this isn't a good idea.

#Usage Seeing the examples of how to use this type in your example main.cpp file left me very confused, even with a comment describing the range. The way you have it now, I have to know how many bits are in a given type's representation, then subtract from that the number of bits I want for the fractional part in order to figure out the range I'll end up with. I also have to make sure that the type I supply has enough bits for the representation. (What happens if I do using Nbr32 = FixedPointNumber<uint8_t, 17>;?)

Furthermore, the type I supply may be unsigned, but the range of the resulting type can still cover negative values. Does it make sense to have an unsigned fixed point type and a signed fixed point type? I'm not sure. But it is odd to supply an unsigned type and have it end up being signed.

I'm not an expert at templates, so I'm not entirely sure what's possible. I think it would be better to have the template take the number of bits for the integral part and the number of bits for the fractional part and choose the type it uses internally based on that and not require a caller to figure it out.

In other words, I'd like to use it like this:

using Fixed16_16 = FixedPointNumber<16, 16>;
using Fixed8_4 = FixedPointNumber<8, 4>;

As I say, I don't know whether it's possible to make that work, but it sure would be nice. If you can get closer to that, it would be great.

#Naming I'm all for long descriptive names. However, I do feel like FixedPointNumber is too long. We don't call float a floatingPointNumber or int an intNumber. I think it would be fine as FixedPoint or even Fixed (though be aware that Apple has used that type name in the past for 16.16 fixed point numbers).

#Future Directions I'd love to see a whole math library for this type. Things like trigonometric and transcendental functions would be helpful. (You might look into cordics if you plan to pursue something like that.)

Source Link
user1118321
  • 11.9k
  • 1
  • 20
  • 46

I recently had my interest in fixed point math piqued as part of a side project I was doing, so this is great to see! Having a C++ class for fixed point numbers would make things so easy!

I'm guessing that the weird formatting is due to copy/paste issues and that your actual code uses indentation. If not, it definitely should.

#Description I notice throughout your comments you say "decimal part". However, you don't use any decimal representation. I was thinking that maybe you were working in BCD or something like that. I would change all references to "decimal" to be "fractional" to be more precise.

#Don't Use using namespace std You've written:

using namespace std;

in your header file. That means that every file which includes your header now has all of the std namespace defined, too. If I have my own max() function that's not in std and I include your header, I will now get conflicts on my max() function. See here for more details.

#Usage Seeing the examples of how to use this type in your example main.cpp file left me very confused, even with a comment describing the range. The way you have it now, I have to know how many bits are in a given type's representation, then subtract from that the number of bits I want for the fractional part in order to figure out the range I'll end up with. I also have to make sure that the type I supply has enough bits for the representation. (What happens if I do using Nbr32 = FixedPointNumber<uint8_t, 17>;?)

Furthermore, the type I supply may be unsigned, but the range of the resulting type can still cover negative values. Does it make sense to have an unsigned fixed point type and a signed fixed point type? I'm not sure. But it is odd to supply an unsigned type and have it end up being signed.

I'm not an expert at templates, so I'm not entirely sure what's possible. I think it would be better to have the template take the number of bits for the integral part and the number of bits for the fractional part and choose the type it uses internally based on that and not require a caller to figure it out.

In other words, I'd like to use it like this:

using Fixed16_16 = FixedPointNumber<16, 16>;
using Fixed8_4 = FixedPointNumber<8, 4>;

As I say, I don't know whether it's possible to make that work, but it sure would be nice. If you can get closer to that, it would be great.

#Naming I'm all for long descriptive names. However, I do feel like FixedPointNumber is too long. We don't call float a floatingPointNumber or int an intNumber. I think it would be fine as FixedPoint or even Fixed (though be aware that Apple has used that type name in the past for 16.16 fixed point numbers).

#Future Directions I'd love to see a whole math library for this type. Things like trigonometric and transcendental functions would be helpful. (You might look into cordics if you plan to pursue something like that.)

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /