FloatToStr with more decimal places displayed ?
Re: FloatToStr with more decimal places displayed ?
Janni - the single precision floating point is derived by a strtofloat conversion for storage and transmission as the 4 bytes of a floating point is smaller than a string literal.
So that's my primary concern. Upto this point everything is fine but what is method to extract a floattostr with more decimal places in the fractional part. ?
My method works perfectly in Delphi but the same does not on the pic. Yes in both cases i use a single/real aa the FP.
If there is a way to extract the fractional part without any operation or loss of accuracy then I'd like to know.
So that's my primary concern. Upto this point everything is fine but what is method to extract a floattostr with more decimal places in the fractional part. ?
My method works perfectly in Delphi but the same does not on the pic. Yes in both cases i use a single/real aa the FP.
If there is a way to extract the fractional part without any operation or loss of accuracy then I'd like to know.
Re: FloatToStr with more decimal places displayed ?
If I understand correctly, there was an accurate number stored in a string, then converted to floating-point representation and you need to restore the original accurate number back to string? As stated earlier, the conversion process means loss of accuracy that cannot be reversed. But the conversion may be replaced by another compacting method, not necessarily involving floating-point numbers.
And now you've got me confused. Is the number of decimal places or the accuracy a problem?So that's my primary concern. Upto this point everything is fine but what is method to extract a floattostr with more decimal places in the fractional part. ?
And I stay confused - single precision, even in different format (Delphi uses IEEE format), means the same limitation of accuracy and you suggest that Delphi plays miracles and packs more information into 4 bytes than possible. Or is it just the number of decimal places problem, whether they're meaningful or not?My method works perfectly in Delphi but the same does not on the pic. Yes in both cases i use a single/real aa the FP.
If there is a way to extract the fractional part without any operation or loss of accuracy then I'd like to know.
-
- Posts: 136
- Joined: 02 Jan 2020 19:00
Re: FloatToStr with more decimal places displayed ?
Transmit the integer and fractional parts of the number separately.
The number of bytes will increase to 8, the number of digits in the fractional part to 7.
Up to 7 significant digits. Regardless of the integer part of the number.
The number of bytes will increase to 8, the number of digits in the fractional part to 7.
Up to 7 significant digits. Regardless of the integer part of the number.
Re: FloatToStr with more decimal places displayed ?
The fractional part may be stored as an integer as well - there's no need of conversion to fp. Dividing the input string (not necessarily at the decimal point if the range of numbers has an upper limit) and converting the two parts to 32 bit integers should suffice.AntiMember wrote: ↑28 Jan 2023 22:21Transmit the integer and fractional parts of the number separately.
Re: FloatToStr with more decimal places displayed ?
I didn't say anything about Delphi performing miracles. I am saying that while Delphi allows for the fractional part to be extracted correctly using a single prec. FP, the same operation on a pic yields a different result.And I stay confused - single precision, even in different format (Delphi uses IEEE format), means the same limitation of accuracy and you suggest that Delphi plays miracles and packs more information into 4 bytes than possible. Or is it just the number of decimal places problem, whether they're meaningful or not?
Probably because we're not using the IEEE format?
So obviously the data width is not the limitation.
For example:
If x = 5.000879965, then getting the fractional part by this operation in Delphi yields a different result.
F (as dword) = x - int(x).
However in Delphi this yields the correct result :
F = (x ) - ( int(x) * 1.0000000)
But not quite on the pic.
In fact let me post the routine tomorrow, I don't have my computer with me today.
Re: FloatToStr with more decimal places displayed ?
It's not difficult either, i use a customized routine myself in existing projects and it works flawlessly.AntiMember wrote: ↑23 Jan 2023 17:39I think it's easier to upgrade to a more powerful processor. Writing a float transformation is not at all an easy task.
-
- Posts: 136
- Joined: 02 Jan 2020 19:00
Re: FloatToStr with more decimal places displayed ?
No problem.
If the source string has a fixed number of digits that will fit in 2x4 bytes.
-
- Posts: 136
- Joined: 02 Jan 2020 19:00
Re: FloatToStr with more decimal places displayed ?
Ohh excellent catch. I totally forgot about this function. Have to try it now. Thanks a ton!!
Re: FloatToStr with more decimal places displayed ?
No, that's what I wrote in exasperation as there are no miracles in arithmetic .
It certainly is but now I see why we did not understand each other . You are convinced that the impossible took place and don't see why it could not be repeated.I am saying that while Delphi allows for the fractional part to be extracted correctly using a single prec. FP, the same operation on a pic yields a different result.
Probably because we're not using the IEEE format?
So obviously the data width is not the limitation.
That would be best as result ofIn fact let me post the routine tomorrow
Code: Select all
var x,y:single;
x:= 5.000879965;
y:= x - int(x);
Re: FloatToStr with more decimal places displayed ?
This function performs exactly the same operation we're discussing.
-
- Posts: 136
- Joined: 02 Jan 2020 19:00
Re: FloatToStr with more decimal places displayed ?
And if the integer part of the number is always less than 65535, you can put it in 6 bytes.AntiMember wrote: ↑28 Jan 2023 22:21Transmit the integer and fractional parts of the number separately.
The number of bytes will increase to 8, the number of digits in the fractional part to 7.
Up to 7 significant digits. Regardless of the integer part of the number.
Last edited by AntiMember on 29 Jan 2023 20:15, edited 2 times in total.
-
- Posts: 136
- Joined: 02 Jan 2020 19:00
Re: FloatToStr with more decimal places displayed ?
Yes, modf is exactly what im looking for.
Thanks @janni, @antimember.
Thanks @janni, @antimember.
-
- Posts: 1
- Joined: 05 Mar 2024 12:02
Re: FloatToStr with more decimal places displayed ?
I totally forgot about this function. Have to try it now. Thanks a ton!! waplus
projectfreetv.onl
projectfreetv.onl