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

  • SEARCH
  • Home
  • 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 8672953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:19:53+00:00 2026-06-12T19:19:53+00:00

The case I have compiled shared library for dyn.loading into R. Then when I

  • 0

The case

I have compiled shared library for dyn.loading into R. Then when I call the wrapper function in R I get result rounded with truncated part after decimal point. I am probably missing something well known as it is my first try to use .C function, but I can’t find what is the cause of rounding. There is my code below.

My C code

#include <freesteam/steam_pT.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <R.h>

// gcc -Wall -fPIC -c Rsteam_h_pT_2.c -o  Rsteam_h_pT_2.o -I/usr/local/include -I/opt/R-2.14.0/lib/R/include -L/usr/local/lib -lfreesteam
// gcc -Wall -shared -o Rsteam_h_pT_2.so Rsteam_h_pT_2.o -I/usr/local/include -I/opt/R-2.14.0/lib/R/include -L/usr/local/lib -lfreesteam

// function
double steam_h_pT(double p, double T){
SteamState S = freesteam_set_pT(p, T);
double s = freesteam_h(S);
return s;
}


// wrapper
double steam_h_pT(double, double);
void steam_h_pT_R_wrapper(double *p, double *T, double *result) { *result = steam_h_pT(*p, *T); }

My R function

steam_h_pT <- function(p_Pa,T_K)
 {
 dyn.load('Rsteam_h_pT.so')
 # Call the C function
 returned_data = .C('steam_h_pT_R_wrapper', p=as.numeric(p_Pa), T= as.numeric(T_K), result=numeric(1))
 # Return the value of the result parameter
 return(returned_data$result)
 }

My R session

> steam_h_pT(100000,400)
[1] 2730398
> str(steam_h_pT(100000,400))
num 2730398
> 

Expected result from original code

bash>./steam_h_pT 1e5 400
2730397.845968

Now, why it gets rounded in R?

  • 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-12T19:19:54+00:00Added an answer on June 12, 2026 at 7:19 pm

    It the representation due to the digits argument to the print function. The number is still stored correctly.

    2730397 + 0.845968
    [1] 2730398
    print(2730397 + 0.845968, digits=15)
    [1] 2730397.845968
    

    You can set the global default with options(digits=15).

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

Sidebar

Related Questions

I need to verify something for which I have doubts. If a shared library
I have my domain split into multiple Entity Framework models. I have some shared
i have a multithreaded library in which i call sleep(3) in different threads. i
I have a static library, Foo, that is used by a shared library, Bar.
I have a really interesting case: I have a site where this is already
The case: I have 2 tables, 'contracts' and 'members' tied with contract.id = members.cid.
In case I have .NET framework installed in my computer + all the necessary
In my case I have panels,but to make it clear I will use buttons
I have a regular .NET application. In this case I have a part that's
I'm new to codeigniter this is my case: I have a homepage with a

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.