LoginSignup
0
0

More than 5 years have passed since last update.

lazuriteでmath.h

Posted at

概要

lazuriteでmath.hやってみた。
doubleは、8バイトだ。

サンプルコード

#include "math0_ide.h"      // Additional Header
#include <math.h>

#define PI        3.14159265
void func0()
{
    Serial.print("\nVarious Math Functions\n");
    Serial.print("the abs of -20 is = ");
    Serial.println_long(abs(-20), DEC);
    Serial.print("the fabs of -12.1 is = ");
    Serial.println_long(fabs(-12.1), DEC);
    Serial.print("the ceil of 12.1 is = ");
    Serial.println_long(ceil(12.1), DEC);
    Serial.print("the floor of 20.9 is = ");
    Serial.println_long(floor(20.9), DEC);
    Serial.print("the fmod of 120 is = ");
    Serial.println_long(fmod(120, 5), DEC);
    Serial.println("the trunc of -20.02 is = ");
    //Serial.println_long(trunc(-20.02), DEC);
}
void func1()
{
    Serial.print("\nExponential, Logarithmic, and Power Functions\n");
    Serial.print("the exp of 4 is = ");
    Serial.println_long(exp(4), DEC);
    Serial.print("the ldexp of 4 is = ");
    Serial.println_long(ldexp(4, 2), DEC);
    Serial.print("the log2 of 1000000 is = ");
    //Serial.println_long(log2(1000000), DEC);
    Serial.print("the log10 of 1000000 is = ");
    Serial.println_long(log10(1000000), DEC);
    //Serial.println("the modf of 8.12345 is = ");
    //double x,
    //  fractpart,
    //  intpart;
    //fractpart = modf(8.12345, &intpart);
    //Serial.print("    Integral part = ");
    //Serial.println(intpart);
    //Serial.print("    Fraction Part = ");
    //Serial.println(modf(8.12345, &intpart));
    Serial.print("the pow of 10 is = ");
    Serial.println_long(pow(10, 2), DEC);
    Serial.print("the sqrt of 36 is = ");
    Serial.println_long(sqrt(36), DEC);
}
void func2()
{
    Serial.print("\nTrigonometic Functions\n");
    Serial.print("the cos of 16 is = ");
    Serial.println_long(cos(16), DEC);
    Serial.print("The acos of 0.9 is = degrees ");
    Serial.println_long(acos(0.9) * (180.0 / PI), DEC);
    Serial.print("the cosh of 16 is = ");
    Serial.println_long(cosh(16), DEC);
    Serial.print("the sin of 16 is = ");
    Serial.println_long(sin(16), DEC);
    Serial.print("the sinh of 16 is = ");
    Serial.println_long(sinh(16), DEC);
    Serial.print("The asin of 0.9 is = degrees ");
    Serial.println_long(asin(0.9) * (180.0 / PI), DEC);
    Serial.print("the tan of 4 is = ");
    Serial.println_long(tan(4), DEC);
    Serial.print("the atan of 4 is = ");
    Serial.println_long(atan(4), DEC);
    Serial.print("the atan2 of 4 is = ");
    Serial.println_long(atan2(4, 2), DEC);
}
void size()
{
    Serial.print("\nSizeof\n");
    Serial.print("Bytes per char: ");
    Serial.println_long((int) sizeof(char), DEC);
    Serial.print("Bytes per unsigned char: ");
    Serial.println_long((int) sizeof(unsigned char), DEC);
    Serial.print("Bytes per short:  ");
    Serial.println_long((int) sizeof(short), DEC);
    Serial.print("Bytes per unsigned short: ");
    Serial.println_long((int) sizeof(unsigned short), DEC);
    Serial.print("Bytes per int: ");
    Serial.println_long((int) sizeof(int), DEC);
    Serial.print("Bytes per unsigned int: ");
    Serial.println_long((int) sizeof(unsigned int), DEC);
    Serial.print("Bytes per long: ");
    Serial.println_long((int) sizeof(long), DEC);
    Serial.print("Bytes per unsigned long: ");
    Serial.println_long((int) sizeof(unsigned long), DEC);
    Serial.print("Bytes per size_t: ");
    Serial.println_long((int) sizeof(size_t), DEC);
    Serial.print("Bytes per float: ");
    Serial.println_long((int) sizeof(float), DEC);
    Serial.print("Bytes per double: ");
    Serial.println_long((int) sizeof(double), DEC);
    Serial.print("Bytes per long double: ");
    Serial.println_long((int) sizeof(long double), DEC);
    Serial.print("Bytes per pointer: ");
    Serial.println_long((int) sizeof(void *), DEC);
}
void setup()
{
    Serial.begin(115200);
    Serial.println("ok");
    size();
    func0();
    func1();
    func2();
}
void loop()
{
    delay(5000);
}




結果

ok

Sizeof
Bytes per char: 1
Bytes per unsigned char: 1
Bytes per short:    2
Bytes per unsigned short: 2
Bytes per int: 2
Bytes per unsigned int: 2
Bytes per long: 4
Bytes per unsigned long: 4
Bytes per size_t: 2
Bytes per float: 4
Bytes per double: 8
Bytes per long double: 8
Bytes per pointer: 2

Various Math Functions
the abs of -20 is = 20
the fabs of -12.1 is = 12
the ceil of 12.1 is = 13
the floor of 20.9 is = 20
the fmod of 120 is = 0
the trunc of -20.02 is = 

Exponential, Logarithmic, and Power Functions
the exp of 4 is = 54
the ldexp of 4 is = 16
the log2 of 1000000 is = the log10 of 1000000 is = 6
the pow of 10 is = 100
the sqrt of 36 is = 6

Trigonometic Functions
the cos of 16 is = 0
The acos of 0.9 is = degrees 25
the cosh of 16 is = 4443055
the sin of 16 is = 0
the sinh of 16 is = 4443055
The asin of 0.9 is = degrees 64
the tan of 4 is = 1
the atan of 4 is = 1
the atan2 of 4 is = 1



以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0