Is there any way to change the rounding mode when doing operations with GMP? Or do I have to use MPFR for that?
Thanks in advance!
Yes, you should use MPFR if you want to control rounding.
The good news is it's relatively trivial to initialize an mpfr_t from an mpf_t, so you can throw it in where you need the rounding control, if you don't want to convert everything over.
See: http://www.mpfr.org/mpfr-current/mpfr.html
Related
I do have code in mpmath that does the main part of what i do, except soling a semidefinite programming in arbitrary precision.
For that, i might be able to use SDPA-GMP, a C++ piece of software that solves a SDP in arbitrary precision using GMP as base arbitrary precision library.
Do you know if there are possibilities to call this from python ? On the over hand, is there somewhere a converter that passed from mpmath objcts to gmp ?
You might have found a solution but here is one: you can use the interface PICOS, save the problem with the extension 'dat-s' and then feed that to SDPA-GMP. This works perfectly and it's rather easy to use.
I have read a few older threads on this issue, and quite frankly the discussion flew over my head a bit. So I'm hoping for some help that I will hopefully be able to follow.
I am programming an STM32 with RTOS (two threads needed). It's a sensor application with some fairly intensive computation on the data gathered (hence the H7). Computation feedback is sent through CDC in the form of a char array, size 12. Nothing difficult. The computation feedback is a float. And this where I am having problems.
Prior to sending the data I need to convert the float to a char[].
my function looks like this:
void ASCII_transmitFloat(float value) {
uint8_t buffer[DEF_ASCII_TX_BUF];
snprintf((char *)buffer, sizeof(buffer), "%11.9f\n", value);
CDC_Transmit_FS(buffer, sizeof(buffer));
}
I am not getting an error, just a crash on the snprintf.
I tried sprintf with the same results
casting my float to a uint32_t and changing the arg type in my function to uint32_t, works. (I'm losing precision so this is not a solution, but tried anyway)
I have the same version of the function for integers, and these work fine as well
oh and I kinda of mickey-moused between uint8_t and char, it's probably as bad as it is ugly, but I haven't found a better way yet
anyhow thanks for any help you can provide
cheers
edit:
Editing in response to the first response.
I had the "use float with printf" option selected in the project properties (MCU settings) - see the screenshot below (not sure if this check box does the same as adding the flag manually)
I tried adding the line -u _printf_float in the linked as suggested in your link, but I have the same results. Crashes when executing the snprintf.
Here is how I fixed the problem.
The problem is known, and ST hasn't fixed the issue since it was first brought up here a year ago, see:
https://community.st.com/s/question/0D50X0000BB1eL7SQJ/bug-cubemx-freertos-projects-corrupt-memory
and here's the recommended fix:
http://www.nadler.com/embedded/newlibAndFreeRTOS.html
A bit over my head so I chose to go the route of using a lighter version of the printf function:
https://github.com/mpaland/printf
I hope it helps someone else with the issue.
Cheers
Probably because float support is not included by default using newlib.
See printf floats with newlib on STM32
This problem happened to me too. I'm not sure yours is same with mine but maybe it can help yoou. I just fixed it and the only thing i did is, i included "stdio.h". Then my warning gone.
Probably very simple question but still trying to figure it out. I got many input doubles provided as strings in this format:
0.99
0.456
etc..
On my dev system when I convert it like:
CDbl(0.456)
It's fine, however on production I get SystemInvalidCastException.
I am not sure but I bet its about different systems symbols like dots or commas.
Is there any way to be independent from system configuration and trade my input strings to be correctly recognized as double?
I tried with this approach and seems it's working. Is this right way to do?
Double.Parse(value, CultureInfo.InvariantCulture)
Yes, it is the right way you're going.
The problem is indeed culture related. If you do not specifiy any culture it will default to the system's culture which will most likely be the reason for the code to work on one system but not on the other.
By specifying the invariant culture you ensure that the systems culture has no effect anymore on the casting.
I have a project on color profile conversion in C++, where the idea is to use CIELAB as transition between RGB and all others (CMY; CMYK; HSV; HSL;...).But I have one big big problem. I have searched everywhere and I cannot find any formula or descrition how could I convert CIELAB to others(CMY; CMYK; HSV; HSL; ...) only I got is what I found here : http://www.easyrgb.com/index.php?X=MATH&H=14#text14 . Can someone please help me with formula or with an idea how to get to them? Thank you so so much.
Regards,
magic :)
Color conversion with mathematical formulas yields very poor results with no serious application. Color systems are far too complex to capture them in simple, closed mathematical formulas let alone in linear formulas.
Good results can only be achived by using color profile files. And the conversion basically invovles interpolation between samples stored in these files.
Have a look at Little CMS. It probably does everything you need. Or if your software will run on Windows, you can use the built-in Windows Color System to do the conversion.
Nice as the Tcl libraries math::bignum and math::bigfloat are, the middle ground between the two needs to be addressed. Namely, bignums which are in different radices and have a radix point.
At present math::bignum only handles integers (afaict) and math::bigfloat won't let you specify different radices to math::bigfloat::fromstr (ditto).
Does anyone know of a library, for any of the major scripting languages (e.g. Tcl, Perl, Python, Ruby, Lua) or less major ones (newLISP for example), which implements bignums in different radices with handling for radix point?
bignumber.js is a Javascript library that handles numbers with a radix point in bases from 2 to 36.
I couldn't find any libraries for this, but I haven't looked for long.
But you can work around the problem similar to what you would do if you want 64-bit datatypes, but only 32-bit datatypes are available. With the libraries you already have, you should be able to represent a number in base b like this:
ABCDEF.GHIJKLMN
can be split to the two bignums ABCDEF and GHIJKLMN. GHIJKLMN in fact is representing GHIJLMN / pow(b, length(GHIJKLMN)) => GHIJKLM / pow(b, 8). Now you can overwrite the operators you need which should be possible for things like +, -, *, /. If you need more things like sqrt, log or pow, this workaround will get too complex and you should really look for a library.
Your best bet is to use GMP (libgmp).
I myself have looked long and hard for a .NET version without luck.