Populate sequence containing NaNChecking if a double (or float) is NaN in C++How do you test to see if a double is equal to NaN?What is the rationale for all comparisons returning false for IEEE754 NaN values?How do you check that a number is NaN in JavaScript?Is it possible to set a number to NaN or infinity?How to turn NaN from parseInt into 0 for an empty string?Why is NaN not equal to NaN?Removing nan values from an arrayHow to check if any value is NaN in a Pandas DataFrameWhat is the difference between (NaN != NaN) and (NaN !== NaN)?
Building a list of products from the elements in another list
How can I close a gap between my fence and my neighbor's that's on his side of the property line?
Why do only some White Walkers shatter into ice chips?
Which module had more 'comfort' in terms of living space, the Lunar Module or the Command module?
What was the design of the Macintosh II's MMU replacement?
Why wasn't the Night King naked in S08E03?
How can I support myself financially as a 17 year old with a loan?
Purpose of のは in this sentence?
Does a card have a keyword if it has the same effect as said keyword?
I need a disease
Position of past participle and extent of the Verbklammer
Getting a W on your transcript for grad school applications
I drew a randomly colored grid of points with tikz, how do I force it to remember the first grid from then on?
Why are prions in animal diets not destroyed by the digestive system?
What are the differences between credential stuffing and password spraying?
Can my company stop me from working overtime?
Prove that the limit exists or does not exist
Missing Piece of Pie - Can you find it?
What matters more when it comes to book covers? Is it ‘professional quality’ or relevancy?
Would Hubble Space Telescope improve black hole image observed by EHT if it joined array of telesopes?
Why didn't the check-in agent recognize my long term visa?
Can there be a single technologically advanced nation, in a continent full of non-technologically advanced nations?
Where can I go to avoid planes overhead?
Using a microphone from the 1930s
Populate sequence containing NaN
Checking if a double (or float) is NaN in C++How do you test to see if a double is equal to NaN?What is the rationale for all comparisons returning false for IEEE754 NaN values?How do you check that a number is NaN in JavaScript?Is it possible to set a number to NaN or infinity?How to turn NaN from parseInt into 0 for an empty string?Why is NaN not equal to NaN?Removing nan values from an arrayHow to check if any value is NaN in a Pandas DataFrameWhat is the difference between (NaN != NaN) and (NaN !== NaN)?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Nim language question here. I want to read a series of floats from stdin (this example: 7, 1, 4, 4, nan, 4) and store it in a seq[float]
type. The input may contain NaNs. But I fail to integrate such outliers.
My code:
var
line: TaintedString
timeSeries: seq[float]
while readline(stdin, line) != false:
echo timeSeries
timeSeries.add(parseFloat(line))
The output:
@[]
@[7.0]
@[7.0, 1.0]
@[7.0, 1.0, 4.0]
@[7.0, 1.0, 4.0, 4.0]
@[7.0, 1.0, 4.0, 4.0, nan]
@[nan, nan, nan, nan, nan, nan]
Facing the first NaN, Nim renders all inputs as NaNs. But I want this (last line of output):
@[7.0, 1.0, 4.0, 4.0, nan, 4.0]
How do I solve it correctly in Nim? Documentation says NaNs are supported…
sequence nan nim
add a comment |
Nim language question here. I want to read a series of floats from stdin (this example: 7, 1, 4, 4, nan, 4) and store it in a seq[float]
type. The input may contain NaNs. But I fail to integrate such outliers.
My code:
var
line: TaintedString
timeSeries: seq[float]
while readline(stdin, line) != false:
echo timeSeries
timeSeries.add(parseFloat(line))
The output:
@[]
@[7.0]
@[7.0, 1.0]
@[7.0, 1.0, 4.0]
@[7.0, 1.0, 4.0, 4.0]
@[7.0, 1.0, 4.0, 4.0, nan]
@[nan, nan, nan, nan, nan, nan]
Facing the first NaN, Nim renders all inputs as NaNs. But I want this (last line of output):
@[7.0, 1.0, 4.0, 4.0, nan, 4.0]
How do I solve it correctly in Nim? Documentation says NaNs are supported…
sequence nan nim
What platform are you on and what back-end compiler are you using?
– Anthon
Mar 23 at 6:39
I am using nim 0.19.4 on Linux/i386, backend compiler is gcc and I have the same effect with -d:release switch. Sorry, I omitted the import statement in above snippet.
– smartmic
Mar 23 at 8:32
add a comment |
Nim language question here. I want to read a series of floats from stdin (this example: 7, 1, 4, 4, nan, 4) and store it in a seq[float]
type. The input may contain NaNs. But I fail to integrate such outliers.
My code:
var
line: TaintedString
timeSeries: seq[float]
while readline(stdin, line) != false:
echo timeSeries
timeSeries.add(parseFloat(line))
The output:
@[]
@[7.0]
@[7.0, 1.0]
@[7.0, 1.0, 4.0]
@[7.0, 1.0, 4.0, 4.0]
@[7.0, 1.0, 4.0, 4.0, nan]
@[nan, nan, nan, nan, nan, nan]
Facing the first NaN, Nim renders all inputs as NaNs. But I want this (last line of output):
@[7.0, 1.0, 4.0, 4.0, nan, 4.0]
How do I solve it correctly in Nim? Documentation says NaNs are supported…
sequence nan nim
Nim language question here. I want to read a series of floats from stdin (this example: 7, 1, 4, 4, nan, 4) and store it in a seq[float]
type. The input may contain NaNs. But I fail to integrate such outliers.
My code:
var
line: TaintedString
timeSeries: seq[float]
while readline(stdin, line) != false:
echo timeSeries
timeSeries.add(parseFloat(line))
The output:
@[]
@[7.0]
@[7.0, 1.0]
@[7.0, 1.0, 4.0]
@[7.0, 1.0, 4.0, 4.0]
@[7.0, 1.0, 4.0, 4.0, nan]
@[nan, nan, nan, nan, nan, nan]
Facing the first NaN, Nim renders all inputs as NaNs. But I want this (last line of output):
@[7.0, 1.0, 4.0, 4.0, nan, 4.0]
How do I solve it correctly in Nim? Documentation says NaNs are supported…
sequence nan nim
sequence nan nim
asked Mar 22 at 22:33
smartmicsmartmic
333310
333310
What platform are you on and what back-end compiler are you using?
– Anthon
Mar 23 at 6:39
I am using nim 0.19.4 on Linux/i386, backend compiler is gcc and I have the same effect with -d:release switch. Sorry, I omitted the import statement in above snippet.
– smartmic
Mar 23 at 8:32
add a comment |
What platform are you on and what back-end compiler are you using?
– Anthon
Mar 23 at 6:39
I am using nim 0.19.4 on Linux/i386, backend compiler is gcc and I have the same effect with -d:release switch. Sorry, I omitted the import statement in above snippet.
– smartmic
Mar 23 at 8:32
What platform are you on and what back-end compiler are you using?
– Anthon
Mar 23 at 6:39
What platform are you on and what back-end compiler are you using?
– Anthon
Mar 23 at 6:39
I am using nim 0.19.4 on Linux/i386, backend compiler is gcc and I have the same effect with -d:release switch. Sorry, I omitted the import statement in above snippet.
– smartmic
Mar 23 at 8:32
I am using nim 0.19.4 on Linux/i386, backend compiler is gcc and I have the same effect with -d:release switch. Sorry, I omitted the import statement in above snippet.
– smartmic
Mar 23 at 8:32
add a comment |
1 Answer
1
active
oldest
votes
Since you echo timeSeries
before you add the next number, the input of the last line with 4
causes the @[7.0, 1.0, 4.0, 4.0, nan]
and it is guesswork what you did after that to get the final output line. Although I doubt there is a valid reason for anything to set every value in the sequence to NaN
, it might be that what your input triggered a bug.
I have not been able to reproduce your output
with your code (adding the required import strutils
) when entering your sequence followed by another 4
, nan
or empty line (the latter erroring on invalid float).
For easier testing, I put your input in a file input.txt
:
7
1
4
4
nan
4
and ran the following on the latest stable nim (Nim Compiler Version 0.19.4 [Linux: amd64]) as the latest devel nim (Nim Compiler Version 0.19.9 [Linux: amd64]):
import strutils
var
line: TaintedString
timeSeries: seq[float]
echo timeSeries
for line in "input.txt".lines:
timeSeries.add(parseFloat(line.strip))
echo timeSeries
(the .strip
is only there to handle trailing spaces in the input that were a result of cut-and-paste and sloppy editing)
Both compilers output:
@[]
@[7.0]
@[7.0, 1.0]
@[7.0, 1.0, 4.0]
@[7.0, 1.0, 4.0, 4.0]
@[7.0, 1.0, 4.0, 4.0, nan]
@[7.0, 1.0, 4.0, 4.0, nan, 4.0]
compiling with -d:release
did not cause any errors either.
I could reproduce your example, it works for me as well. I will investigate why it failed in my initial try (could not reproduce this quickly though)
– smartmic
Mar 23 at 8:49
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308634%2fpopulate-sequence-containing-nan%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Since you echo timeSeries
before you add the next number, the input of the last line with 4
causes the @[7.0, 1.0, 4.0, 4.0, nan]
and it is guesswork what you did after that to get the final output line. Although I doubt there is a valid reason for anything to set every value in the sequence to NaN
, it might be that what your input triggered a bug.
I have not been able to reproduce your output
with your code (adding the required import strutils
) when entering your sequence followed by another 4
, nan
or empty line (the latter erroring on invalid float).
For easier testing, I put your input in a file input.txt
:
7
1
4
4
nan
4
and ran the following on the latest stable nim (Nim Compiler Version 0.19.4 [Linux: amd64]) as the latest devel nim (Nim Compiler Version 0.19.9 [Linux: amd64]):
import strutils
var
line: TaintedString
timeSeries: seq[float]
echo timeSeries
for line in "input.txt".lines:
timeSeries.add(parseFloat(line.strip))
echo timeSeries
(the .strip
is only there to handle trailing spaces in the input that were a result of cut-and-paste and sloppy editing)
Both compilers output:
@[]
@[7.0]
@[7.0, 1.0]
@[7.0, 1.0, 4.0]
@[7.0, 1.0, 4.0, 4.0]
@[7.0, 1.0, 4.0, 4.0, nan]
@[7.0, 1.0, 4.0, 4.0, nan, 4.0]
compiling with -d:release
did not cause any errors either.
I could reproduce your example, it works for me as well. I will investigate why it failed in my initial try (could not reproduce this quickly though)
– smartmic
Mar 23 at 8:49
add a comment |
Since you echo timeSeries
before you add the next number, the input of the last line with 4
causes the @[7.0, 1.0, 4.0, 4.0, nan]
and it is guesswork what you did after that to get the final output line. Although I doubt there is a valid reason for anything to set every value in the sequence to NaN
, it might be that what your input triggered a bug.
I have not been able to reproduce your output
with your code (adding the required import strutils
) when entering your sequence followed by another 4
, nan
or empty line (the latter erroring on invalid float).
For easier testing, I put your input in a file input.txt
:
7
1
4
4
nan
4
and ran the following on the latest stable nim (Nim Compiler Version 0.19.4 [Linux: amd64]) as the latest devel nim (Nim Compiler Version 0.19.9 [Linux: amd64]):
import strutils
var
line: TaintedString
timeSeries: seq[float]
echo timeSeries
for line in "input.txt".lines:
timeSeries.add(parseFloat(line.strip))
echo timeSeries
(the .strip
is only there to handle trailing spaces in the input that were a result of cut-and-paste and sloppy editing)
Both compilers output:
@[]
@[7.0]
@[7.0, 1.0]
@[7.0, 1.0, 4.0]
@[7.0, 1.0, 4.0, 4.0]
@[7.0, 1.0, 4.0, 4.0, nan]
@[7.0, 1.0, 4.0, 4.0, nan, 4.0]
compiling with -d:release
did not cause any errors either.
I could reproduce your example, it works for me as well. I will investigate why it failed in my initial try (could not reproduce this quickly though)
– smartmic
Mar 23 at 8:49
add a comment |
Since you echo timeSeries
before you add the next number, the input of the last line with 4
causes the @[7.0, 1.0, 4.0, 4.0, nan]
and it is guesswork what you did after that to get the final output line. Although I doubt there is a valid reason for anything to set every value in the sequence to NaN
, it might be that what your input triggered a bug.
I have not been able to reproduce your output
with your code (adding the required import strutils
) when entering your sequence followed by another 4
, nan
or empty line (the latter erroring on invalid float).
For easier testing, I put your input in a file input.txt
:
7
1
4
4
nan
4
and ran the following on the latest stable nim (Nim Compiler Version 0.19.4 [Linux: amd64]) as the latest devel nim (Nim Compiler Version 0.19.9 [Linux: amd64]):
import strutils
var
line: TaintedString
timeSeries: seq[float]
echo timeSeries
for line in "input.txt".lines:
timeSeries.add(parseFloat(line.strip))
echo timeSeries
(the .strip
is only there to handle trailing spaces in the input that were a result of cut-and-paste and sloppy editing)
Both compilers output:
@[]
@[7.0]
@[7.0, 1.0]
@[7.0, 1.0, 4.0]
@[7.0, 1.0, 4.0, 4.0]
@[7.0, 1.0, 4.0, 4.0, nan]
@[7.0, 1.0, 4.0, 4.0, nan, 4.0]
compiling with -d:release
did not cause any errors either.
Since you echo timeSeries
before you add the next number, the input of the last line with 4
causes the @[7.0, 1.0, 4.0, 4.0, nan]
and it is guesswork what you did after that to get the final output line. Although I doubt there is a valid reason for anything to set every value in the sequence to NaN
, it might be that what your input triggered a bug.
I have not been able to reproduce your output
with your code (adding the required import strutils
) when entering your sequence followed by another 4
, nan
or empty line (the latter erroring on invalid float).
For easier testing, I put your input in a file input.txt
:
7
1
4
4
nan
4
and ran the following on the latest stable nim (Nim Compiler Version 0.19.4 [Linux: amd64]) as the latest devel nim (Nim Compiler Version 0.19.9 [Linux: amd64]):
import strutils
var
line: TaintedString
timeSeries: seq[float]
echo timeSeries
for line in "input.txt".lines:
timeSeries.add(parseFloat(line.strip))
echo timeSeries
(the .strip
is only there to handle trailing spaces in the input that were a result of cut-and-paste and sloppy editing)
Both compilers output:
@[]
@[7.0]
@[7.0, 1.0]
@[7.0, 1.0, 4.0]
@[7.0, 1.0, 4.0, 4.0]
@[7.0, 1.0, 4.0, 4.0, nan]
@[7.0, 1.0, 4.0, 4.0, nan, 4.0]
compiling with -d:release
did not cause any errors either.
edited Apr 6 at 7:55
answered Mar 23 at 6:39
AnthonAnthon
33.1k1798152
33.1k1798152
I could reproduce your example, it works for me as well. I will investigate why it failed in my initial try (could not reproduce this quickly though)
– smartmic
Mar 23 at 8:49
add a comment |
I could reproduce your example, it works for me as well. I will investigate why it failed in my initial try (could not reproduce this quickly though)
– smartmic
Mar 23 at 8:49
I could reproduce your example, it works for me as well. I will investigate why it failed in my initial try (could not reproduce this quickly though)
– smartmic
Mar 23 at 8:49
I could reproduce your example, it works for me as well. I will investigate why it failed in my initial try (could not reproduce this quickly though)
– smartmic
Mar 23 at 8:49
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308634%2fpopulate-sequence-containing-nan%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What platform are you on and what back-end compiler are you using?
– Anthon
Mar 23 at 6:39
I am using nim 0.19.4 on Linux/i386, backend compiler is gcc and I have the same effect with -d:release switch. Sorry, I omitted the import statement in above snippet.
– smartmic
Mar 23 at 8:32