Joining large and small float into array - difference in result

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Joining large and small float into array - difference in result

phofman
Hi,

I am encountering a weird problem.

I need to place float timestamp (time()) and another float into one vector.

debug> a
a =    1.70434168467182e-06
debug> timestamp
timestamp =  1552340333.21415
debug> a
a =    1.70434168467182e-06
debug> b = [timestamp, a]
b =

    1.55234035200000e+09   1.70434168467182e-06


Please note the difference in the original timestamp and the first item
in vector b. It is not only rounding since the whole number is different
(1552340333 vs. 1552340352).


This rounded and modified value is stored into file using the save()
method in default text mode, I see the exact text value. With load() it
gets loaded correctly - as the changed 1.55234035200000e+09.

When trying the same in octave prompt (not in debug mode) I get correct
values:


 >> a = 1.70434168467182e-06
a =    1.70434168467182e-06
 >> timestamp = 1552340333.21415
 >> b = [timestamp, a]
b =

    1.55234033321415e+09   1.70434168467182e-06

Please how can I preserve (and save to file) the the original timestamp
float value while the program runs?

Octave 4.2.2, Linux.

Thanks a lot,

Pavel.


Reply | Threaded
Open this post in threaded view
|

Re: Joining large and small float into array - difference in result - SOLVED

phofman

Dne 11. 03. 19 v 23:10 Pavel Hofman napsal(a):

> Hi,
>
> I am encountering a weird problem.
>
> I need to place float timestamp (time()) and another float into one vector.
>
> debug> a
> a =    1.70434168467182e-06
> debug> timestamp
> timestamp =  1552340333.21415
> debug> a
> a =    1.70434168467182e-06
> debug> b = [timestamp, a]
> b =
>
>     1.55234035200000e+09   1.70434168467182e-06
>
My apology - single vs. double. I changed everything to double and it
works fine now.

Pavel.