Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8298709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:53:05+00:00 2026-06-08T15:53:05+00:00

This is a reproducible C++ program: #include <RInside.h> #include <Rcpp.h> int main (int argc,

  • 0

This is a reproducible C++ program:

#include <RInside.h>
#include <Rcpp.h>

int main (int argc, char *argv[])
{
    RInside R (argc, argv);
    SEXP ans = R.parseEval ("m <- 40.702147");

    Rcpp::NumericVector v (ans);           

    for (int i=0; i< v.size(); i++) 
    {           
        std::cout << "In C++ element " << i << " is " << v[i] << std::endl;
    }

    return 0;
}

Makefile’s here:

## -*- mode: make; tab-width: 8; -*-
##
## Simple Makefile
##
## TODO: 
##  proper configure for non-Debian file locations,   [ Done ]
##  allow RHOME to be set for non-default R etc

## comment this out if you need a different version of R, 
## and set set R_HOME accordingly as an environment variable
R_HOME :=       $(shell R RHOME)

sources :=      $(wildcard *.cpp)
programs :=         $(sources:.cpp=)


## include headers and libraries for R 
RCPPFLAGS :=        $(shell $(R_HOME)/bin/R CMD config --cppflags)
RLDFLAGS :=         $(shell $(R_HOME)/bin/R CMD config --ldflags)
RBLAS :=        $(shell $(R_HOME)/bin/R CMD config BLAS_LIBS)
RLAPACK :=      $(shell $(R_HOME)/bin/R CMD config LAPACK_LIBS)

## if you need to set an rpath to R itself, also uncomment
#RRPATH :=      -Wl,-rpath,$(R_HOME)/lib

## include headers and libraries for Rcpp interface classes
RCPPINCL :=         $(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
RCPPLIBS :=         $(shell echo 'Rcpp:::LdFlags()'  | $(R_HOME)/bin/R --vanilla --slave)


## include headers and libraries for RInside embedding classes
RINSIDEINCL :=      $(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
RINSIDELIBS :=      $(shell echo 'RInside:::LdFlags()'  | $(R_HOME)/bin/R --vanilla --slave)

## compiler etc settings used in default make rules
CXX :=          $(shell $(R_HOME)/bin/R CMD config CXX)
CPPFLAGS :=         -Wall $(shell $(R_HOME)/bin/R CMD config CPPFLAGS)
CXXFLAGS :=         $(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL) $(shell $(R_HOME)/bin/R CMD config CXXFLAGS)
LDLIBS :=       $(RLDFLAGS) $(RRPATH) $(RBLAS) $(RLAPACK) $(RCPPLIBS) $(RINSIDELIBS)

all:            $(programs)
            @test -x /usr/bin/strip && strip $^

run:            $(programs)
            @for p in $(programs); do echo; echo "Running $$p:"; ./$$p; done

clean:
            rm -vf $(programs)
            rm -vrf *.dSYM

runAll:
            for p in $(programs); do echo "Running $$p"; ./$$p; done

Output of this program:

In C++ element 0 is 40.7021

The problem is that the value 40.702147 is getting “truncated” to 40.7021.
I want it full.
What is the way out?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T15:53:06+00:00Added an answer on June 8, 2026 at 3:53 pm

    The value itself is not being truncated (a), the cout output stream is using the defaults for output.

    You can look into the iomanip header to find ways to force a specific output format, such as:

    std::cout << std::setprecision (9) << v[i] << '\n';
    

    This complete program here:

    #include <iostream>
    #include <iomanip>
    
    int main (void) {
        double d = 40.702147;
        std::cout << d << '\n';
        std::cout << std::setprecision (9) << d << '\n';
        return 0;
    }
    

    outputs:

    40.7021
    40.702147
    

    (a): Keep in mind it may be truncated if it cannot be represented exactly as an IEEE754 double precision value but that’s not the case here – doubles have about fifteen decimal digits of precision and you’re only seeing six.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This problem is not readily reproducible in a simple example here but was wondering
I have the following code: int get_int(void) { char input[10]; fgets(input, 10, stdin); //
I ran into this problem today in IE6 (but is reproducible on all recent
EDIT : This reproducible SIGSEGV happens on a Linux machine with more than one
This is a reproducible example: a <- 0.05 za.2 <- qnorm(1-a/2) b <- 0.20
please consider this reproducible example: from PIL import Image import numpy as np import
this is my first question in here, and I would like to ask if
This question is directly related to this SO question I posed about 15 minutes
This question is kind of a follow up to this question I asked a
This should be a simple one: I have an observableArray object called To in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.