Hacker News new | past | comments | ask | show | jobs | submit | seg_fault's comments login

Awesome! The fold up mechanism is a great idea to make it look clean, when there is no party and it also saves the hardware from dust :D


My type is a bit simpler. But I think the approach is the same. After all, boost's type has much more math functions implemented. I don't have exp, sqrt...


If I understand this correctly GMP has a flexible mantissa with no limitations during runtime.

In fas you have to specify the sizes (of mantissa and exponent) during compile time. So the size of this type is fixed. Thus, there is no heap involved.


Removed it.


You should put the copyright notice back and (optionally) add a license. Removing the notice from your code changes nothing, that does not waive or remove your copyright. You still have the copyrights to your code by default, and you should. Don’t react to silly comments on the internet by feeding them.

If you really don’t want the copyrights, you can use the CC0 license from Creative Commons. That would allow people to use your code any way they want with no restrictions (which means they are legally allowed to use it commercially, remove the author notice, re-license modified versions, redistribute the code, etc.). However, you do not need to waive your copyrights entirely in order to license your code as open source. You can choose between a variety of licensing terms, while still being very open and liberal about sharing. Try the Creative Commons license chooser https://chooser-beta.creativecommons.org/. Or look through open source licenses. Standardized SPDX IDs are gaining popularity since it helps with some automation workflows. https://opensource.org/licenses https://spdx.org/licenses/

Since you left the author note, maybe you would like an attribution license like one of these popular choices (both available with SPDX IDs): https://opensource.org/license/bsd-3-clause https://creativecommons.org/licenses/by-sa/4.0/

If you don’t add a license, then your code remains under strict copyright and people are not legally allowed to use it in their own projects, regardless of whether you have a copyright notice in the comments. Leaving out the copyright notice might be confusing, especially given this thread. The recommended practice is to include both the copyright notice and the license in comments or a license file.


Somebody wants to use it? :D I thought about something like where people can use it but have to make changed public. I am just curious, what should be changed. But I dont think there is actually a real world use case.


Sounds like you prefer copyleft licenses. I suggest MPL-2.0 or some variety of (L)GPL as they are the most well-known ones.


I don't get what you mean. I thought they specify how the type can be used?


The cppreference page says:

> If the program adds specializations for std::is_fundamental or std::is_fundamental_v, the behavior is undefined.

This is an oversimplification. The actual rule is https://eel.is/c++draft/library#namespace.std-2 .

> the specialization meets the standard library requirements for the original template.

For is_fundamental<YourClassType> it means that is_fundamental<YourClassType>::value must be false, as YourClassType is not a fundamental type, as defined in https://eel.is/c++draft/basic.fundamental#17 .

Some traits are just not designed to be customization points.


Technically, you're not supposed to add your own specialisations to the `std` namespace


In general this isn’t true (i guess it is in this specific context). For example I believe it’s totally expected to specialize std hash


I’ve also done this with hash… though given the footguns scattered about, I wouldn’t be surprised if it broke the spec.


That is a completely intended way to use std::hash, along with a few other functions like std::tuple_size and std::tuple_element.


Thank you :)


Actually you can specify the numeric limits of the mantissa and the exponent. They can be specified as template arguments[0]. So you could do:

      Float<uint8_t, // type of the mantissa
            uint8_t, // type of the exponent
            0,       // lowest possible value of the mantissa
            4095,    // highest possible value of the mantissa
            0,       // lowest possible value of the exponent
            7>       // highest possible value of the exponent
The Float then simulates an unsigned 12bit mantissa and a 3bit exponent. Sure it still takes 16 bytes. But you could create a union with bitfields where you shrink that even further.

[0] https://github.com/clemensmanert/fas/blob/58f9effbe6c13ab334...


Can you go in the other direction? Higher exponent and mantissa than regular float/double?


Sure.

    Float<int64_t, int64_t>
Gives you a signed Mantissa with 64 bit and a signed Exponent with 64bit. Since there are numeric limits for int64_t available, Float knows the max and the min value.

You could get even bigger ranges for Float by implementing your own big integer type.


Rounding: actually it just cuts off. I have not spent much time to think about how to specify and implement the different rounding modes. Maybe some day...

Thanks for the hint to the paper. I also faced these issues. Thus, I provided a constructor which accepts mantissa and exponent as values. Very handy for the unittests.


By cutting off do you mean that it correctly rounds towards zero? Maybe you can implement rounding to closest by just doing the calculation in a one digit wider mantissa with rounding to zero and observing the last digit, at least for an even base. It won't be rounding to even though, but for that a 2 digit wider mantissa is probably enough.

Rounding to nearest with an odd base doesn't seem to be as straightforwardly implementable from rounding to zero calculations at a higher precision.


I remember that I tried that some time ago. Especially the multiplication was tough, but I can not recall where I gave up. When I find some time, I will pick it up again :)


I do. And a lot of my neighbors. In Germany it is pretty common to to have a few chicken in the backyard in countryside areas. My parents life in the Munich suburban belt and even have a rooster in their flock. Their neighbors have not complained so far.

They eat snails and all the kitchen scaprs and I seldom have to buy eggs. Besides, it is so lovely to watch them in the garden. Their social live and their communication within the flock is very interesting to watch.

There are also a lot of nice hacker projects out: self closing chicken coop, monitoring, live cams.

And they really look nice, there are so many beautiful breeds, just type chicken breed in duckduckgo image search.


Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: