Coder Social home page Coder Social logo

nelua-mpfr's Introduction

nelua-mpfr

Nelua bindings for the GNU MPFR library, version 4.1.

The MPFR library is a C library for multiple-precision floating-point computations with correct rounding.

The MPFR documentation is available here.

Prerequisites

  • The GNU MPFR library must be installed in the system or otherwise available to the C compiler.
  • GNU MPFR requires, as a hard dependency, the GNU GMP library.

Usage

Drop the mpfr.nelua file in your project and use it with a require 'mpfr'.

In restricted environments where stdio.h is not available you can define the NELUA_MPFR_NO_STDIO symbol in Nelua's preprocessor to remove all IO functions that require the FILE type to be available:

## NELUA_MPFR_NO_STDIO = 1
require `mpfr`

Example

The main type used by GNU MPFR is the mpfr_t record.

Thanks to the automatic referencing performed by the nelua compiler, variables defined as mpfr_t can be passed to most of the functions without the & operator.

However, some functions, namely those using varargs, are defined in such a way that require the reference operator. For an example look at the mpfr_printf call in the following program.

require 'mpfr'

local s: mpfr_t

-- Init 's' with 100 bits of precision and set its value
mpfr_init2(s, 100)
mpfr_set_str(s, '1.3337612', 10, MPFR_RNDN)

-- Multiply by 42 and print the result to stdout
mpfr_mul_ui(s, s, 42, MPFR_RNDN)
mpfr_printf("1.3337612 * 42 is: %.30Rf\n", &s)

-- Clean-up
mpfr_clear(s)
mpfr_free_cache()

A more comprehensive example is available in the mpfr-test.nelua file.

Please refer to the MPFR documentation for more datails.

nelua-mpfr's People

Contributors

acisternino avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.